Linux Debian 系统的单网卡绑定多个IP地址的操作步骤

在Debian系统添加新IP,你只需要修改下 /etc/network/interfaces 文件就可以了,即在eth0接口上绑定更多的IP地址

我们首先要编辑网卡添加新IP地址的配置文件命令如下:

sudo vi /etc/network/interfaces

安装了nano更方便一些使用

nano /etc/network/interfaces

输入以上命令之后,我们就进入了编辑器修改配置文件的界面。
举例:
单网卡“eth0添加“192.168.1.2”和“192.168.1.3”这2个IP例进行演示,命令代码如下:

注意,这里很重要,几个ip就加上几个:

auto eth0
auto eth0:0
auto eth0:1

默认网卡eth0的IP地址

iface eth0 inet static
address 192.168.1.1 #主机IP地址
netmask 255.255.255.0 #子网掩码
gateway 192.168.1.254 #网关地址

网卡eth0的增加第1个IP地址

iface eth0:0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254

网卡eth0的增加第2个IP地址

iface eth0:1 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

当以上内容编辑完成后,执行如下命令生效:

sudo /etc/init.d/networking restart

以上命令执行失败,重启服务器即可

参考样板:
打开文件编辑

nano /etc/network/interfaces

编辑内容

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
auto eno1
auto eno1:1
auto eno1:2
auto eno1:3
auto eno1:4
iface lo inet loopback

# The primary network interface
allow-hotplug eno1
iface eno1 inet static
        address 1.209.190.202/29
        gateway 1.209.190.201

iface eno1:1 inet static
        address 1.209.190.203/29
        gateway 1.209.190.201

iface eno1:2 inet static
        address 1.209.190.204/29
        gateway 1.209.190.201

iface eno1:3 inet static
        address 1.209.190.205/29
        gateway 1.209.190.201

iface eno1:4 inet static
        address 1.209.190.206/29
        gateway 1.209.190.201
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 8.8.8.8

重启网络

/etc/init.d/networking restart
Last modification:September 20th, 2024 at 01:58 pm

Leave a Comment