2021-05-12 14:32:11
CentOS 7中網路設定圖文詳解
檢視CentOS 7網路介面資訊
- 檢視所有活動網路介面的資訊
- ifconfig命令
[root@localhost ~]# ifconfig //檢視網路介面資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 6139 bytes 3599390 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2483 bytes 330519 (322.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 84 bytes 7500 (7.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 84 bytes 7500 (7.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:d9:de:d2 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- 檢視指定網路介面資訊
- ifconfig 網路介面
[root@localhost ~]# ifconfig ens33 //檢視ens33網路介面資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 6183 bytes 3602858 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2505 bytes 334073 (326.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
檢視主機名稱
- 檢視或設定當前主機名
- hostname命令
[root@localhost ~]# hostname //檢視主機名稱 localhost.localdomain
- 更改主機名稱
- hostnamectl set-hostname [主機名稱]
[root@localhost ~]# hostnamectl set-hostname http01 //更改主機名 [root@localhost ~]# su //切換使用者,重新整理主機名 [root@http01 ~]# hostname //檢視主機名稱 http01
檢視路由表條目
- 檢視路由表
- route命令
[root@http01 ~]# route //檢視路由表 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
檢視網路連線情況
-
檢視系統的網路連線狀態、路由表、介面統計等資訊
- netstat命令
netstat [選項]
- 常用選項
-a :全部
-n:數位格式顯示
-p:協定
-t :tcp
-u :udp
-r:路由
[root@http01 ~]# netstat -antp //檢視以數位格式顯示全部TCP協定埠的網路連線情況 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1308/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 983/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 985/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1292/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4840/sshd: root@pts tcp 0 0 192.168.144.133:22 192.168.144.1:54734 ESTABLISHED 4840/sshd: root@pts tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 2373/httpd tcp6 0 0 :::22 :::* LISTEN 983/sshd tcp6 0 0 ::1:631 :::* LISTEN 985/cupsd tcp6 0 0 ::1:25 :::* LISTEN 1292/master tcp6 0 0 ::1:6010 :::* LISTEN 4840/sshd: root@pts [root@http01 ~]# netstat -nuap //檢視以數位格式顯示全部UDP協定埠的網路連線情況 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0:36571 0.0.0.0:* 788/dhclient udp 0 0 0.0.0.0:47956 0.0.0.0:* 578/avahi-daemon: r udp 0 0 192.168.122.1:53 0.0.0.0:* 1308/dnsmasq udp 0 0 0.0.0.0:67 0.0.0.0:* 1308/dnsmasq udp 0 0 0.0.0.0:68 0.0.0.0:* 788/dhclient udp 0 0 0.0.0.0:5353 0.0.0.0:* 578/avahi-daemon: r udp 0 0 127.0.0.1:323 0.0.0.0:* 636/chronyd udp6 0 0 :::57996 :::* 788/dhclient udp6 0 0 ::1:323 :::* 636/chronyd [root@http01 ~]# netstat -r //檢視路由資訊,與route命令作用相同 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default gateway 0.0.0.0 UG 0 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
網路測試連線
-
測試網路通訊性
- ping命令
ping [主機名]/[IP地址]
[root@http01 ~]# ping 192.168.100.10 //測試網路通訊 PING 192.168.100.10 (192.168.100.10) 56(84) bytes of data. 64 bytes from 192.168.100.10: icmp_seq=1 ttl=128 time=0.860 ms 64 bytes from 192.168.100.10: icmp_seq=2 ttl=128 time=0.530 ms 64 bytes from 192.168.100.10: icmp_seq=3 ttl=128 time=0.514 ms 64 bytes from 192.168.100.10: icmp_seq=4 ttl=128 time=0.465 ms
跟蹤封包
-
測試從當前主機到目的主機之間經過的網路節點
- traceroute命令
traceroute 目標主機地址
[root@http01 ~]# traceroute 192.168.100.10 traceroute to 192.168.100.10 (192.168.100.10), 30 hops max, 60 byte packets 1 gateway (192.168.144.2) 0.320 ms 0.255 ms 0.223 ms 2 * * * 3 * * * 4 * * *
域名解析
-
測試DNS域名解析
- nslookup命令
nslookup [目標主機地址]/[目標DNS地址]
[root@http01 ~]# nslookup www.baidu.com Server: 192.168.144.2 Address: 192.168.144.2#53 Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 183.232.231.172 Name: www.a.shifen.com Address: 183.232.231.174
設定網路引數的方式
臨時設定——使用命令調整網路引數
-
簡單、快速,可直接修改執行中的網路引數
-
一般只適合在偵錯網路的過程中使用
- 重新啟動以後,所做的修改將會失效
固定設定——通過組態檔修改網路引數
- 修改各項網路引數的組態檔
- 適合對伺服器設定固定引數時使用
- 需要過載網路服務或者重新啟動以後才會生效
設定網路介面的引數
-
臨時設定網路介面的IP地址、子網掩碼
ifconfig 介面名 IP地址 [netmask(子網掩碼)]
[root@http01 ~]# ifconfig ens33 //檢視ens33介面IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 42 bytes 3966 (3.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 86 bytes 9346 (9.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@http01 ~]# ifconfig ens33 192.168.144.138/24 //設定臨時IP地址 [root@http01 ~]# ifconfig ens33 //檢視是否成功設定 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.138 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 2660 bytes 3613441 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 844 bytes 57384 (56.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@http01 ~]# systemctl restart network //重新啟動網路服務 [root@http01 ~]# ifconfig ens33 //檢視IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) //設定的IP地址失效 RX packets 2708 bytes 3618185 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 894 bytes 63590 (62.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
設定固定網路介面的IP地址、子網掩碼
設定固定的網路介面IP地址、子網掩碼,需要在網路介面的組態檔中更改組態檔來完成。
-
網路介面組態檔
/etc/sysconfig/network-scripts/
-
重新啟動network網路服務
systemctl restart network
[root@http01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //進入編輯網絡卡組態檔 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=staticl //將DHCP更改為staticl DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.144.138 //輸入要設定的IP地址 NETMAS=255.255.255.0 //輸入子網掩碼 GATEWAY=192.168.144.1 //輸入閘道器地址 [root@http01 ~]# systemctl restart network //重新啟動網路服務 [root@http01 ~]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.138 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::20c:29ff:fe5b:d3a0 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) //地址設定成功 RX packets 3832 bytes 3715216 (3.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1558 bytes 160876 (157.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
禁用或者重新啟用網絡卡
- 禁用網絡卡
ifconfig 網路介面 down
- 重新啟用網絡卡
ifconfig 網路介面 up
[root@localhost ~]# ifconfig ens33 down //禁用網絡卡 [root@localhost ~]# ifconfig ens33 //檢視網絡卡資訊,無IP地址連線 ens33: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 459 bytes 495831 (484.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 240 bytes 22865 (22.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33 up //重新啟用網絡卡 [root@localhost ~]# ifconfig ens33 //檢視網絡卡資訊,成功獲取IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 463 bytes 496409 (484.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 264 bytes 26630 (26.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
虛擬網路介面
- 虛擬網路介面是指共用一個網絡卡,同一網絡卡可以配多個IP地址,不管存取哪一個IP地址都能存取同一伺服器。(當不想用虛擬網絡卡時直接禁用虛擬網絡卡即可)
ifconfig 介面名:序號 IP地址
[root@localhost ~]# ifconfig ens33:0 192.168.144.140 //在ens33網絡卡上新增虛擬網絡卡,序列號為0 [root@localhost ~]# ifconfig //檢視網絡卡資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 653 bytes 512686 (500.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 373 bytes 39897 (38.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //建立的虛擬網絡卡 inet 192.168.144.140 netmask 255.255.255.0 broadcast 192.168.144.255 ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) ...//省略部分內容...
設定路由記錄
-
新增到指定網段的路由記錄
- route add -net 網段地址 gw IP地址(閘道器)
-
刪除到指定網段的路由記錄
- route del -net 網段地址
-
刪除路由表中預設閘道器記錄
- route del default gw IP地址
- 向路由表中新增預設閘道器記錄
- route add default gw IP地址
[root@localhost ~]# route //檢視路由表 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route add -net 192.168.100.0/24 gw 192.168.144.1 //新增網段 [root@localhost ~]# route //檢視路由表是否新增網段 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.100.0 192.168.144.1 255.255.255.0 UG 0 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route del -net 192.168.100.0/24 //刪除新增的網段 [root@localhost ~]# route //檢視路由表,看新增的網段是否刪除 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route add default gw 192.168.144.1 //新增預設閘道器 [root@localhost ~]# route //檢視是否成功新增預設閘道器 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 ens33 default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route del default gw 192.168.144.1 //刪除新增的預設閘道器 [root@localhost ~]# route //檢視路由表是否成功刪除 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
主機名稱組態檔
-
儲存全域性網路設定,主要包括主機名資訊
/etc/sysconfig/network//etc/hostname
在CentOS 6中若要修改主機名可以執行“vim /etc/sysconfig/network”修改組態檔,而在CentOS 7中我們可以執行“vim /etc/hostname”就可以去修改主機名組態檔了。
[root@localhost ~]# vim /etc/hostname //進入編輯主機名組態檔 localhost.localdomain //當前主機名 如若修改可以直接在編輯器修改主機名 ~ ~ ~ ~ ~ ~
域名解析組態檔
-
指定為本機體提供DNS解析的伺服器地址(對改檔案的修改將會立即生效)
- /etc/resolv.conf
- 格式
- nameserver IP地址
[root@localhost ~]# vim /etc/resolv.conf # Generated by NetworkManager search localdomain nameserver 192.168.144.2 ~ ~ ~ ~
本地主機對映檔案
在本地主機對映檔案中新增對映記錄,當存取新增的記錄網站時,將會直接向新增的對映記錄IP地址傳送web請求,省略了向DNS伺服器解析IP地址的過程。
-
儲存主機名與IP地址的對映記錄
- /etc/hosts
- hosts檔案和DNS伺服器的比較
- 預設情況下,系統首先從hosts檔案查詢解析記錄
- hosts檔案只對當前的主機有效
- hosts檔案可減少DNS查詢過程,從而加快存取速度
補充內容:
雙網絡卡的建立
在日常生產活動中難免會遇到需要建立雙網絡卡的情況,這裡我們來看看如何建立雙網絡卡
1、首先在虛擬機器Linux作業系統中新增一塊物理網絡卡,然後檢視網路介面資訊,確定是否成功新增網路
[root@localhost ~]# ifconfig //檢視網介面資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3415 bytes 740748 (723.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1725 bytes 201799 (197.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //新新增的物理網絡卡 inet 192.168.144.141 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::deb1:3cec:3e26:5ec2 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet) RX packets 85 bytes 6069 (5.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 30 bytes 4667 (4.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、這個時候我們檢視網絡卡組態檔目錄,看是否有新增的網絡卡組態檔
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ //進入網絡卡組態檔目錄 [root@localhost network-scripts]# ls //檢視,這個時候時沒有新新增的網絡卡ens36的組態檔的 ifcfg-ens33 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functions ifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6 ifdown ifdown-post ifup ifup-isdn ifup-Team ifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPort ifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnel ifdown-ib ifdown-sit ifup-eth ifup-post ifup-wireless ifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-global
3、因為沒有ens36網絡卡的組態檔,我們就沒有辦法給ens36指定固定的地址的。下面我們就把ens36與ens33這兩個網絡卡全部設為僅主機相連模式,然後再檢視網路介面資訊。
[root@localhost ~]# ifconfig //檢視網路介面資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //無獲取IP地址 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3578 bytes 754392 (736.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1812 bytes 215065 (210.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //無發獲取IP地址 inet6 fe80::deb1:3cec:3e26:5ec2 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet) RX packets 160 bytes 12321 (12.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 7865 (7.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我在這裡無法獲取IP地址是因為的VMware虛擬機器中DHCP服務關掉了,所以無法獲取地址。
4、這個時候我們就給這兩個物理網絡卡配固定地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //編輯網絡卡資訊 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static //dhcp更改為static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.10 //輸入設定IP地址 NETMAS=255.255.255.0 //輸入設定子網掩碼 GATEWAY=192.168.100.0 //輸入設定閘道器 ~ ~ ~ ~ ~ ~ ~ :wq [root@localhost ~]# service network restart //重新啟動網路服務 Restarting network (via systemctl): [ 確定 ] [root@localhost ~]# ifconfig //檢視網路介面資訊,看設定的地址是否生效 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3642 bytes 771191 (753.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1948 bytes 239617 (234.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
下面我們進入網絡卡組態檔目錄,這時候時沒有ens36網絡卡的組態檔的,我們就需要把ens33的組態檔直接複製,更改為ens36的組態檔,然後把組態檔的內容更改就可以了
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ //進入網絡卡組態檔目錄 [root@localhost network-scripts]# ls //檢視 ifcfg-ens33 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort [root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36 //複製ens33組態檔 [root@localhost network-scripts]# ls //檢視 ifcfg-ens33 ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort ifcfg-ens36 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team [root@localhost network-scripts]# vim ifcfg-ens36 //進入編輯ens36組態檔 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens36 //更改33為36 DEVICE=ens36 //更改33為36 ONBOOT=yes IPADDR=192.168.10.10 //更改IP地址網段 NETMAS=255.255.255.0 GATEWAY=192.168.10.0 //更改閘道器地址 ~ ~ 注意,組態檔裡面的UUID條目要刪掉,讓系統自動識別新增就可以了(UUID不可相同 ) ~ ~ ~ ~ ~ ~ :wq [root@localhost network-scripts]# service network restart //重新啟動網路服務 Restarting network (via systemctl): [ 確定 ] [root@localhost network-scripts]# ifconfig //檢視網絡卡資訊 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3705 bytes 788818 (770.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1978 bytes 243934 (238.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //成功獲取IP地址 inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::f6eb:23e3:3afb:fef4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet) RX packets 248 bytes 33751 (32.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 280 bytes 49781 (48.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
相關文章