方式一:
缺点:每一个ip不知道对应那个网络名
1) vi /etc/sysconfig/network-scripts/ifcfg-default
# 有可能你的不是: ifcfg-default ,而是/ifcfg-ens3377776,没有你自己随便建一个也行,格式是:ifcfg-xxx 。
将里面内容全部删除,重新改为如下内容:
BOOTPROTO=none
DEVICE=enp0s17 #要配置的网卡名称
IPADDR=192.168.1.10 #要设置的ip1
PREFIX=24 ##要设置的ip的子网掩码
IPADDR1=10.168.1.10#要设置的ip2
PREFIX1=24
IPADDR2=40.168.1.10#要设置的ip3
PREFIX2=24
IPADDR3=70.168.1.10#要设置的ip4
PREFIX3=24
GATEWAY=192.168.1.1 #默认网关
DNS1=115.181.79.253 #域名解析服务器地址
ONBOOT=yes #开机启动
2)重启网络
service network restart
3)查看结果: ip addr show
效果如下:
[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:5d:9c:b8 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.11/24 brd 192.168.1.255 scope global enp0s17
valid_lft forever preferred_lft forever
inet 10.168.1.11/24 brd 10.168.1.255 scope global enp0s17
valid_lft forever preferred_lft forever
inet 70.168.1.11/24 brd 70.168.1.255 scope global enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::4ee1:aceb:b704:4b2d/64 scope link
valid_lft forever preferred_lft forever
方式二:
缺点:比较麻烦
1)
vi /etc/sysconfig/network-scripts/ifcfg-xxx
#xxx必须是你的网卡名!
输入:
DEVICE=enp0s17 #网卡名
ONBOOT=yes
BOOTPROTO="static" # static 或 none
IPADDR=192.168.1.11 #第一个ip地址
PREFIX=24
GATEWAY=192.168.1.1 #网关
DNS1=115.181.79.253#DNS服务器地址
2) vi /etc/sysconfig/network-scripts/ifcfg-xxx:NNN
#NNN名字随意,这里我取:yy1
输入:
DEVICE=enp0s17:yy1 #必须这种格式
IPADDR=100.148.1.11
PREFIX=24
输入:
#NNN名字随意,这里我取:yy2
DEVICE=enp0s17:yy2
IPADDR=173.222.67.11
PREFIX=24
4)你可以写任意多个ifcfg-xxx:NNN。然后保存。重启网络
service network restart
5)查看结果:
[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:5d:9c:b8 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s17
valid_lft forever preferred_lft forever
inet 173.222.67.10/24 brd 173.222.67.255 scope globalenp0s17:yy2
valid_lft forever preferred_lft forever
inet 100.148.1.10/24 brd 100.148.1.255 scope globalenp0s17:yy1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe5d:9cb8/64 scope link
valid_lft forever preferred_lft forever
方式三、
缺点:重启网络后就消失了,只能重启电脑还原。
#相当于每次开机执行:
ip addr add {ip地址/网关} dev { 网卡名} label {ip别名 }比如:
ip addr add 172.25.215.40/24 dev enp0s17 label enp0s17:one
1)vi /etc/locale.conf
添加该 命令:
ip addr add 172.25.215.40/24 dev enp0s17 label enp0s17:one
ip addr add 192.168.1.10/24 dev enp0s17 label enp0s17:two
ip addr add 100.148.1.10/24 dev enp0s17 label enp0s17:three
2)重启电脑
来源:CSDN
作者:昕water
链接:https://blog.csdn.net/qq_15304853/article/details/78750773