CentOS、Ubuntu配置网卡子接口

CentOS

# ip addr add 10.1.1.1/24 dev eth0 lable eth0:0

以上为临时配置,重启失效。若需永久保存,增加网络配置文件

# vim /etc/sysconfig/network-script/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=10.1.1.1
PREFIX=24
BOOTPROTO=none
ONPARENT=yes
ONBOOT=yes

重启网络服务

# service network restart    #CentOS6
# systemctl restart network.services    #CentOS7

Ubuntu16

# ip addr add 10.1.1.1/24 dev ens0 lable ens0:0

修改网络配置文件,永久保存

# vim /etc/network/interfaces
auto ens3:0
iface ens3:0 inet static
address 10.1.1.1
netmask 255.255.255.0

重启网络服务

# service network restart

 注:子接口不可配置网关,否则会影响系统路由表。

原文地址:https://www.cnblogs.com/st-jun/p/7736045.html