首页  编辑  

Linux单个网卡配置多个IP地址

Tags: /计算机文档/Linux & Unix/   Date Created:

Linux、Ubuntu,单网卡多IP地址配置

Single Network Adapter/Network Card with mulit-IP address configuration for Ubuntu/Linux/Debian
sudo vi /etc/network/interfaces
类似下面即可:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet dhcp

auto eth0:0
iface eth0:0 inet static
address 192.168.1.253
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1

auto eth0:1
iface eth0:1 inet static
address 192.168.200.253
netmask 255.255.255.0
#gateway 192.168.200.1   默认网关只能有一个, Only one gateway allowed!
dns-nameservers 208.67.222.222 8.8.8.8

auto usb0
iface usb0 inet static
address 192.168.2.2
netmask 255.255.255.0
dns-nameservers 208.67.222.222 8.8.8.8
适用于Ubuntu 系统,其他linux系统可能类似
如果重启后,eth0:0不工作,你需要修改
/etc/init.d/rc.local,在里面添加一行:
ifup eth0:0
ifup eth0:1
....
eth0:0 is configured but not listed in ifconfig output after reboot
if manual run /etc/init.d/networking restart or "ifup eth0:0", it works fine?

以上适合于Ubuntu系统,其他系统类似!