1. 程式人生 > >網絡基礎配置

網絡基礎配置

dns/ip配置

管理網絡

1.ip基礎知識
(1).ipv4
(2)進制32位-----10進制

172.25.0.10/255.255.255.0
172.25.0.10:ip地址
255.255.255.0:子網掩碼
子網掩碼255位對應的ip位為網絡位
子網掩碼0對應的ip位為主機位

技術分享

2.配置ip


<<圖形化>>
1.圖形界面


nm-connection-editor
2.文本化圖形
nmtui

<<命令>>
ifconfig 網卡 ip netmask ##臨時設定

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24
nmcli connection delete westos
nmcli connection show

技術分享nmcli connection down westos
nmcli connection up westos
nmcli connection modify "eth0" ipv4.addresses newip/24

技術分享nmcli connection modify "eth0" ipv4.method <auto|manual>

nmcli device connect eth0
nmcli device disconnect eth0

技術分享nmcli device show

技術分享nmcli device status

技術分享

<<文件>>
dhcp # #動態獲取
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ##接口使用設備
BOOTPROTO=dhcp ##網卡工作模式
ONBOOT=yes ##網絡服務開啟時自動激活
NAME=eth0 ##網絡接口名稱

技術分享:wq
systemctl restart network

static|none ##靜態網絡
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ##設備
BOOTPROTO=static|none ##設備工作方式
ONBOOT=yes ##開啟網絡服務激活設備
NAME=eth0 ##網絡接口名稱
IPADDR=172.25.254.125 ##IP
NETMASK=255.255.255.0 | PREFIX=24 ##子網掩碼

技術分享

3.gateway 網關

1.路由器
主要功能是用來作nat的
dnat 目的地地址轉換
snat 源地址轉換

2.網關
路由器上和自己處在同一個網段的那個ip

3.設定網關
systemctl stop NetwrokManager
vim /etc/sysconfig/network ##全局網關

技術分享

GATEWAY=網關ip

vim /etc/sysconfig/network-scripts/ifcfg-網卡配置文件 ##網卡接口網關
GATEWAY=網關ip

systemctl restart netwrok

route -n ##查詢網關
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 (網關)172.25.0.254 0.0.0.0 UG 0 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

技術分享

4.dns
1.dns
dns是一臺服務器
這太服務器提供了回答客戶主機名和ip對應關系的功能

2.設定dns
vim /etc/resolv.conf
nameserver dns服務器ip

技術分享

vim /etc/sysconfig/network-scripts/ifcfg-網卡配置文件
DNS1=dns服務器ip

技術分享

3.本地解析文件
vim /etc/hosts
ip 主機名稱

4.本地解析文件和dns讀取的優先級調整
/etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服務器,那個在前面那個優先

技術分享

技術分享

技術分享

技術分享

技術分享

##註意:上圖是配置dns必備的,需要先開啟火墻,配置火墻服務(必不可少),當你完成上述工作後,在虛擬機上就可以通過真機的WiFi上網了。


網絡基礎配置