CentOS 7 is provided in the network

View network interface information

  • View all active network interfaces
    • ifconfigcommand
[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
  • Check specify the network interface information
    • 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

View Host Name

  • View or set the current host name
    • hostnamecommand
[root@localhost ~]# hostname //查看主机名称
localhost.localdomain
  • Change the hostname
    • hostnamectl set-hostname [主机名称]
[root@localhost ~]# hostnamectl set-hostname http01    //更改主机名
[root@localhost ~]# su                 //切换用户,刷新主机名
[root@http01 ~]# hostname           //查看主机名称
http01

View the routing table entries

  • View the routing table
    • routecommand
[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

View network connections

  • View the status of the network connection system, routing tables, interface statistics and other information

    • netstatcommand

    netstat [选项]

    • Common options

    -a : All

    -n: Digital format

    -p:protocol

    -ttcp

    -uudp

    -r:routing

[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

Network connection tests

  • Testing of network communications

    • pingcommand

    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

Trace packet

  • Test network node passes between the host and the destination from the current

    • traceroutecommand

    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

  • Test DNS name resolution

    • nslookupcommand

    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

Setting network parameters manner

Temporary Configuration - to adjust the network parameters using the command

  • Simple, fast, can directly modify the operation of the network parameters

  • Generally only suitable for use in the process of debugging the network

  • After the restart, the changes made will fail

Fixed - to modify the network configuration file parameters

  • Modify the configuration file of the network parameters
  • Suitable for use when fixed parameter settings server
  • Network services need to reload or restart to take effect later

Setting parameters of the network interface

  • Temporarily set the network interface IP address, subnet mask

    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
  • Set a fixed network interface IP address, subnet mask,

    Set a fixed network interface IP address, subnet mask, we need to change the configuration file on the network interface in the configuration file to complete.

  • The network interface configuration files

    /etc/sysconfig/network-scripts/

  • Restart network services 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
  • Disable or re-activate the card

    • Disable network card

    ifconfig 网络接口 down

    • Re-activate the card
      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
  • Virtual Network Interface

    • Virtual Network Interface refers to share a network card, the same card can be equipped with multiple IP addresses, regardless of which IP addresses can access the same server access. (When not want to use the virtual card directly disable virtual card required)

    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)
        ...//省略部分内容...

Set the routing record

  • Add a route to record the specified network.

    • route add -net 网段地址 gw IP地址(网关)
  • Delete the route to record the specified network.

    • route del -net 网段地址
  • Delete the default gateway routing table records

    • route del default gw IP地址
  • Add records to the default gateway routing table
    • 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

Host name of the profile

  • Save Global network settings, including host name information

    /etc/sysconfig/network//etc/hostname

    In CentOS 6the To modify the hostname can perform “vim /etc/sysconfig/network”modify the configuration file, and in the CentOS 7middle we can perform “vim /etc/hostname”on it to change the machine name of the configuration file.

[root@localhost ~]# vim /etc/hostname   //进入编辑主机名配置文件

localhost.localdomain       //当前主机名   如若修改可以直接在编辑器修改主机名
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         
~                                                            

DNS configuration files

  • Designated as the body providing DNS resolution server address (to change the file modification will be effective immediately)

    • /etc/resolv.conf
  • format
    • nameserver IP地址
[root@localhost ~]# vim /etc/resolv.conf 

# Generated by NetworkManager
search localdomain
nameserver 192.168.144.2
~                                                                                         
~                                                                                         
~                                                                                         
~                                                                                         

Local host mapping file

In the local host mapping file, add the mapping records, when added to the site visit records will be sent web requests, omit the process of resolving IP addresses to the DNS server directly to the IP address mapping records added.

  • Save the host name and IPmapping records address

    • /etc/hosts
  • hostsFile and DNScompare server
    • By default, the system first from hostsFind parse log files
    • hostsFile is only valid for the current host
    • hostsFiles can reduce the DNSquery process, thus speeding up access speed

to add on:

Establishing dual-card

Will inevitably encounter situations need to establish dual-card in daily production activities, here we take a look at how to create a dual-NIC

1, first add the virtual machine Linux operating system in a physical network adapter, and then view the network interface information to determine whether the network successfully added

CentOS 7 is provided in the networkCentOS 7 is provided in the network

[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, this time we see the network card configuration file directory to see if there are network card configuration file to add

[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, because no configuration file ens36 card, we have no way to specify a fixed address to ens36. Let's put ens36 and ens33 two network cards connected all set to host only mode, and then view network interface information.

CentOS 7 is provided in the network

[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

I can not obtain an IP address here because of a VMware virtual machine DHCP service turned off, so I can not get an address.

CentOS 7 is provided in the network

4, this time we give these two physical cards with a fixed address

[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

Here we enter the NIC configuration file directory, this time there is no profile ens36 card, we need to ens33 configuration files directly copy, change ens36 configuration file, and then change the contents of the configuration file on it

[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

Guess you like

Origin blog.51cto.com/14473285/2434770