CentOS,在一張名稱為 enp0s8 的網路卡,設定多個IP
方法一:
使用 ifconfig 指令動態新增IP(網卡重啟後失效)
#新增一個別名 enp0s8:xyz (較常見使用 enp0s8:0、enp0s8:1、...),用來設定新增的IP $ ifconfig enp0s8:xyz 192.168.56.111/24 up #關閉別名為 enp0s8:xyz 的設定 $ ifconfig enp0s8:xyz down
方法二:
使用 ip 指令動態新增(網卡重啟後失效)
#不設定別名,直接新增IP $ ip addr add 192.168.56.111/24 dev enp0s8 #新增一個別名 enp0s8:xyz (較常見使用 enp0s8:0、enp0s8:1、...),用來設定新增的IP $ ip addr add 192.168.56.111/24 dev enp0s8 label enp0s8:xyz #刪除指定的IP設定 $ ip addr del 192.168.56.111/24 dev enp0s8 label enp0s8:xyz
方法三:
於原網路卡設定檔,參數加後綴,設定新增的IP
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s8 ....... ###第1個新增的IP IPADDR1=192.168.56.111 PREFIX1=24 ###第2個新增的IP IPADDR2=192.168.56.112 PREFIX2=24
重啟網路 $ systemctl restart network 或 $ ifdown enp0s8 ; ifup enp0s8;
方法四:
新增網路卡別名設定檔,設定新增的IP
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s8:xyz1 DEVICE="enp0s8:xyz1" #/usr/share/doc/initscripts-9.49.53/sysconfig.txt #ONBOOT="yes" #(not valid for alias devices; use ONPARENT) ONPARENT="yes" IPADDR="192.168.56.111" PREFIX="24" #NETMASK=255.255.255.0
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s8:xyz2 DEVICE="enp0s8:xyz2" #ONBOOT="yes" #(not valid for alias devices; use ONPARENT) ONPARENT="yes" IPADDR="192.168.56.112" PREFIX="24" #NETMASK=255.255.255.0
啟用新增的網卡別名設定 $ ifup enp0s8:xyz1 $ ifup enp0s8:xyz2
參考:
- https://www.itread01.com/content/1554141442.html
網卡別別名設置 - https://www.jianshu.com/p/ff29a974b416
静态/动态方式配置网卡别名(又称网卡子ip) - https://www.garron.me/en/linux/add-secondary-ip-linux.html
Linux add a second IP address, permanent or temporary - https://computingforgeeks.com/adding-a-secondary-ip-address-to-rhel-centos-8-network-interface/
Add Secondary IP Address To CentOS / RHEL Network Interfa - https://community.spiceworks.com/topic/545859-add-secondary-ip-to-one-interface-in-centos-7
Add secondary IP to one interface in CentOS 7 - https://wiki.centos.org/zh-tw/TipsAndTricks/VirtualIPAddresses
虛擬 IP 位址 - https://serverfault.com/questions/567119/virtual-network-interfaces-starting-on-boot-even-though-they-are-set-to-onboot-n
Virtual network interfaces starting on boot even though they are set to onboot=no , what could be the reason?
沒有留言:
張貼留言