手機版
你好,游客 登錄 注冊
背景:
閱讀新聞

CentOS 7中網絡設置圖文詳解

[日期:2019-10-10] 來源:Linux社區  作者:SiceLc [字體: ]

查看CentOS 7網絡接口信息

  • 查看所有活動網絡接口的信息
    • ifconfig命令
[[email protected] ~]# 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 網絡接口
[[email protected] ~]# 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命令
[[email protected] ~]# hostname //查看主機名稱
localhost.localdomain
  • 更改主機名稱
    • hostnamectl set-hostname [主機名稱]
[[email protected] ~]# hostnamectl set-hostname http01    //更改主機名
[[email protected] ~]# su                 //切換用戶,刷新主機名
[[email protected] ~]# hostname           //查看主機名稱
http01

查看路由表條目

  • 查看路由表
    • route命令
[[email protected] ~]# 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:路由

[[email protected] ~]# 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: [email protected] 
tcp        0      0 192.168.144.133:22      192.168.144.1:54734     ESTABLISHED 4840/sshd: [email protected] 
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: [email protected]
[[email protected] ~]# 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        
[[email protected] ~]# 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地址]

[[email protected] ~]# 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 目標主機地址

[[email protected] ~]# 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地址]

[[email protected] ~]# 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(子網掩碼)]

[[email protected] ~]# 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

[[email protected] ~]# ifconfig ens33 192.168.144.138/24    //設置臨時IP地址
[[email protected] ~]# 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
[[email protected] ~]# systemctl restart network           //重啟網絡服務
[[email protected] ~]# 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

[[email protected] ~]# 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        //輸入網關地址
[[email protected] ~]# systemctl restart network    //重啟網絡服務
[[email protected] ~]# 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
[[email protected] ~]# ifconfig ens33 down              //禁用網卡
[[email protected] ~]# 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
[[email protected] ~]# ifconfig ens33 up            //重新激活網卡
[[email protected] ~]# 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地址

[[email protected] ~]# ifconfig ens33:0 192.168.144.140 //在ens33網卡上添加虛擬網卡,序列號為0
[[email protected] ~]# 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地址
[[email protected] ~]# 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
[[email protected] ~]# route add -net 192.168.100.0/24 gw 192.168.144.1  //添加網段
[[email protected] ~]# 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
[[email protected] ~]# route del -net 192.168.100.0/24  //刪除添加的網段
[[email protected] ~]# 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
[[email protected] ~]# route add default gw 192.168.144.1  //添加默認網關
[[email protected] ~]# 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
[[email protected] ~]# route del default gw 192.168.144.1   //刪除添加的默認網關
[[email protected] ~]# 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”就可以去修改主機名配置文件了。

[[email protected] ~]# vim /etc/hostname   //進入編輯主機名配置文件

localhost.localdomain       //當前主機名   如若修改可以直接在編輯器修改主機名
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                            

域名解析配置文件

  • 指定為本機體提供DNS解析的服務器地址(對改文件的修改將會立即生效)

    • /etc/resolv.conf
  • 格式
    • nameserver IP地址
[[email protected] ~]# 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操作系統中添加一塊物理網卡,然后查看網絡接口信息,確定是否成功添加網絡

CentOS 7網絡設置圖文詳解CentOS 7網絡設置圖文詳解

[[email protected] ~]# 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、這個時候我們查看網卡配置文件目錄,看是否有添加的網卡配置文件

[[email protected] ~]# cd /etc/sysconfig/network-scripts/   //進入網卡配置文件目錄
[[email protected] 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這兩個網卡全部設為僅主機相連模式,然后再查看網絡接口信息。

CentOS 7網絡設置圖文詳解

[[email protected] ~]# 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服務關掉了,所以無法獲取地址。

CentOS 7網絡設置圖文詳解

4、這個時候我們就給這兩個物理網卡配固定地址

[[email protected] ~]# 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
[[email protected] ~]# service network restart       //重啟網絡服務
Restarting network (via systemctl):                        [  確定  ]
[[email protected] ~]# 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的配置文件,然后把配置文件的內容更改就可以了

[[email protected] ~]# cd /etc/sysconfig/network-scripts/    //進入網卡配置文件目錄
[[email protected] 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
[[email protected] network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36  //復制ens33配置文件
[[email protected] 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
[[email protected] 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

[[email protected] network-scripts]# service network restart   //重新啟動網絡服務
Restarting network (via systemctl):                        [  確定  ]
[[email protected] 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

Linux公社的RSS地址http://www.vnrggh.live/rssFeed.aspx

本文永久更新鏈接地址http://www.vnrggh.live/Linux/2019-10/160969.htm

linux
相關資訊       CentOS 7網絡設置 
本文評論   查看全部評論 (0)
表情: 表情 姓名: 字數

       

評論聲明
  • 尊重網上道德,遵守中華人民共和國的各項有關法律法規
  • 承擔一切因您的行為而直接或間接導致的民事或刑事法律責任
  • 本站管理人員有權保留或刪除其管轄留言中的任意內容
  • 本站有權在網站內轉載或引用您的評論
  • 參與本評論即表明您已經閱讀并接受上述條款
彩票平台