CentOS7配置单网卡多IP

说明

现在需要给服务器的第一块网卡em1添加多个IP地址对应两个网段

原有配置文件

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="no"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="em1"
UUID="c145cf5f-a2b5-4678-a0e0-75ec94705faa"
DEVICE="em1"
ONBOOT="yes"
IPADDR0="192.168.8.11"
IPADDR1="10.0.0.11"
PREFIX="24"
GATEWAY0="192.168.8.1"
GATEWAY1="10.0.0.1"

复制配置文件

cp /etc/sysconfig/network-scripts/ifcfg-em1 /etc/sysconfig/network-scripts/ifcfg-em1:0

修改配置文件

vim /etc/sysconfig/network-scripts/ifcfg-em1:0

DEVICE="em1:0"
ONBOOT="yes"
IPADDR="10.0.0.10"
PREFIX="24"
GATEWAY="10.0.0.1"

重启服务

systemctl restart network

测试访问

$ ping -c 5 192.168.8.11
PING 192.168.8.11 (192.168.8.11) 56(84) bytes of data.
64 bytes from 192.168.8.11: icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from 192.168.8.11: icmp_seq=2 ttl=64 time=0.033 ms
64 bytes from 192.168.8.11: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.8.11: icmp_seq=4 ttl=64 time=0.035 ms
64 bytes from 192.168.8.11: icmp_seq=5 ttl=64 time=0.034 ms

--- 192.168.8.11 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4003ms
rtt min/avg/max/mdev = 0.033/0.035/0.041/0.004 ms

$ ping -c 5 10.0.0.11
PING 10.0.0.11 (10.0.0.11) 56(84) bytes of data.
64 bytes from 10.0.0.11: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 10.0.0.11: icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 10.0.0.11: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 10.0.0.11: icmp_seq=4 ttl=64 time=0.033 ms
64 bytes from 10.0.0.11: icmp_seq=5 ttl=64 time=0.033 ms

--- 10.0.0.11 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 0.033/0.033/0.034/0.005 ms

你可能感兴趣的:(Linux,存档,操作系统,网络,CentOS)