CentOS 网卡配置多个 IP 地址

CentOS Linux About 2,333 words

查看网卡

ip a命令查看

ip address

输出:lo本地回环地址、eth0网卡

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:01:02:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::fbd8:2087:6c9a:fbd9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

ifconfig命令查看

ifconfig

输出:lo本地回环地址、eth0网卡

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.100  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::fbd8:2087:6c9a:fbd9  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:01:02:0a  txqueuelen 1000  (Ethernet)
        RX packets 1456059  bytes 2065701363 (1.9 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 580685  bytes 88488942 (84.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 218961  bytes 19877589 (18.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 218961  bytes 19877589 (18.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0 配置多 IP

方法一

编辑ifcfg-eth0配置文件

vim /etc/sysconfig/network-scripts/ifcfg-eth0

指定IPADDR1IPADDR2(可以从0开始,如果要配置3个及以上,IPADDR3数字累加)

TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR1=192.168.0.100
NETMASK1=255.255.255.0
GATEWAY1=192.168.0.1
DNS1=114.114.114.114
IPADDR2=10.17.0.100
NETMASK2=255.255.255.0
GATEWAY2=10.17.0.1
DNS2=8.8.8.8

方法二

创建eth0网卡的别名文件,以:0结尾。

/etc/sysconfig/network-scripts/ifcfg-eth0:0

添加内容

TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS=114.114.114.114

重启网卡

sudo service network restart
Views: 1,650 · Posted: 2022-04-01

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh