配置网卡子接口
一台服务器:192.168.182.137
子接口的命名规则:ifcfg-ens33:0,ifcfg-ens33:1等等
1、关闭防火墙、selinux
[root@localhost ~]# systemctl stop firewalld # 关闭防火墙
[root@localhost ~]# systemctl disable firewalld # 开机自动关闭防火墙
[root@localhost ~]# getenforce #查看selinux的状态
enforcing
[root@localhost ~]# setenforce 0 # 临时关闭selinux
[root@localhost ~]# vim /etc/selinux/config #永久关闭selinux,但是要重启机器才会生效(reboot)
SELINUX=disabled #将enforcing修改为disabled
2、配置子接口文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifdown ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global
[root@localhost network-scripts]# vim ifcfg-ens33
[root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-ens33.bak
[root@localhost network-scripts]# vim ifcfg-ens33 #ip地址为192.168.184.110
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.184.110
NETMASK=255.255.255.0
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0 #ip地址为192.168.184.111
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33:0"
DEVICE="ens33:0"
ONBOOT="yes"
IPADDR=192.168.184.111
NETMASK=255.255.255.0
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:1
[root@localhost network-scripts]# vim ifcfg-ens33:1 #ip地址为192.168.184.112
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33:1"
DEVICE="ens33:1"
ONBOOT="yes"
IPADDR=192.168.184.112
NETMASK=255.255.255.0
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-eth ifdown-sit ifup-eth ifup-ppp init.ipv6-global
ifcfg-ens33:0 ifdown-ippp ifdown-Team ifup-ippp ifup-routes network-functions
ifcfg-ens33:1 ifdown-ipv6 ifdown-TeamPort ifup-ipv6 ifup-sit network-functions-ipv6
ifcfg-ens33.bak ifdown-isdn ifdown-tunnel ifup-isdn ifup-Team
ifcfg-lo ifdown-post ifup ifup-plip ifup-TeamPort
ifdown ifdown-ppp ifup-aliases ifup-plusb ifup-tunnel
ifdown-bnep ifdown-routes ifup-bnep ifup-post ifup-wireless
3、重启网络服务
[root@localhost ~]# systemctl restart network
4、测试配置
重启网卡后,如果用工具远程连接的服务器,当前的连接会断开,可以在重新登录新设置的ip地址。
[c:\~]$ ssh 192.168.184.110
Connecting to 192.168.184.110:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Sep 9 18:53:39 2019 from 192.168.184.1
[root@localhost ~]# ip a |grep ens33 #可以查看到设置的子接口地址
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 192.168.184.110/24 brd 192.168.184.255 scope global ens33
inet 192.168.184.111/24 brd 192.168.184.255 scope global secondary ens33:0
inet 192.168.184.112/24 brd 192.168.184.255 scope global secondary ens33:1
也可以新建页面,使用ssh登录来测试三个ip的连通性,三个ip能相互ping通即可,也可以ssh远程登录去验证。