CentOS配置网卡子接口

配置网卡子接口

正常情况,只有一块网卡,这里的网卡名为 enp0s25,但有时候需要多个IP配置在一个服务器上,就需要网卡子接口实现

1
2
3
[root@host-0 network-scripts]# ls
ifcfg-enp0s25 ifdown ......
......

复制这个网卡配置文件并改名为enp0s25:0 , enp0s25:1

需要几个子接口就复制几个文件

1
2
3
cp ifcfg-enp0s25 ifcfg-enp0s25:0
cp ifcfg-enp0s25 ifcfg-enp0s25:1
......

将子接口的配置文件的 NAMEDEVICE 改名为和网卡配置文件一样的名称,每个子接口的ip地址要不一样

1
2
3
4
5
6
7
8
[root@host-0 network-scripts]# cat ifcfg-enp0s25:0
TYPE=Ethernet
BOOTPROTO=static
DEVICE=enp0s25:0
NAME=enp0s25:0
ONBOOT=yes
IPADDR=10.10.10.200
NETMASK=255.255.255.0

重启网络服务

1
systemctl restart network

可以看到ip已经生效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@host-0 network-scripts]# ifconfig 
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.20 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::6af7:28ff:fe2e:e230 prefixlen 64 scopeid 0x20<link>
ether 68:f7:28:2e:e2:30 txqueuelen 1000 (Ethernet)
RX packets 553217 bytes 301601649 (287.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 482998 bytes 61025212 (58.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf0600000-f0620000

enp0s25:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.10.200 netmask 255.255.255.0 broadcast 10.10.10.255
ether 68:f7:28:2e:e2:30 txqueuelen 1000 (Ethernet)
device interrupt 20 memory 0xf0600000-f0620000

......

[root@host-0 network-scripts]# ping 10.10.10.200
PING 10.10.10.200 (10.10.10.200) 56(84) bytes of data.
64 bytes from 10.10.10.200: icmp_seq=1 ttl=64 time=0.051 ms
64 bytes from 10.10.10.200: icmp_seq=2 ttl=64 time=0.066 ms
64 bytes from 10.10.10.200: icmp_seq=3 ttl=64 time=0.058 ms
^C
--- 10.10.10.200 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.051/0.058/0.066/0.008 ms

删除子接口

将 ifcfg-xxx:n 配置文件删除
重启网路服务

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2018-2024 Outsrkem
  • 访问人数: | 浏览次数:

      请我喝杯咖啡吧~

      支付宝
      微信