linux ubuntu网卡配置ip地址,Ubuntu下单网卡多IP地址的配置

本文详细介绍了如何在Linux系统中删除默认配置文件并修改网卡配置,以添加多个静态IP地址。通过备份配置、编辑interfaces文件并重启网络服务,成功实现了12个IP地址的配置,并通过ifconfig命令验证了配置效果。
摘要由CSDN通过智能技术生成

[1]删除用户默认配置文件

由于在默认清空下,配置文件是系统自动生成的用户设备配置文件保存在

/etc/udev/rule.d/下面

#cp /etc/udev/rule.d /etc/udev/rule.d.bak.0 -R

# rm /etc/udev/rule.d/*

[2]修改网卡配置文件,添加多IP配置

#vim /etc/network/interfaces

为如下内容

auto eth0

iface eth0 inet static

address 213.128.82.162

netmask 255.255.255.240

network 213.128.82.160

broadcast 213.128.82.175

gateway 213.128.82.161

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 195.175.39.39

dns-search altinsoft.net

auto eth0:0

iface eth0:0 inet static

address 213.128.82.163

netmask 255.255.255.240

auto eth0:1

network 213.128.82.160

broadcast 213.128.82.175

gateway 213.128.82.161

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 195.175.39.39

dns-search altinsoft.net

auto eth0:0

iface eth0:0 inet static

address 213.128.82.163

netmask 255.255.255.240

auto eth0:1

iface eth0:1 inet static

address 213.128.82.164

netmask 255.255.255.240

auto eth0:2

iface eth0:2 inet static

address 213.128.82.165

netmask 255.255.255.240

auto eth0:3

iface eth0:3 inet static

address 213.128.82.166

netmask 255.255.255.240

auto eth0:4

iface eth0:4 inet static

address 213.128.82.167

netmask 255.255.255.240

............

实验环境,我添加了12个IP地址

[3]让配置生效

#/etc/init.d/networking restart

[4]检查效果

root@ubuntu:~# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.162  Bcast:213.128.82.175  Mask:255.255.255.240

inet6 addr: fe80::226:b9ff:fe86:13fb/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:134 errors:0 dropped:0 overruns:0 frame:0

TX packets:134 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:15404 (15.4 KB)  TX bytes:17608 (17.6 KB)

eth0:0    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.163  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:1    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.164  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.165  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:3    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.166  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:4    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.167  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:5    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.168  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.169  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:7    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.170  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:8    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.171  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:9    Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.172  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:10   Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.173  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:11   Link encap:Ethernet  HWaddr 00:26:b9:86:13:fb

inet addr:213.128.82.174  Bcast:213.128.82.175  Mask:255.255.255.240

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:65536  Metric:1

RX packets:155 errors:0 dropped:0 overruns:0 frame:0

TX packets:155 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:14630 (14.6 KB)  TX bytes:14630 (14.6 KB)

可以看到三个IP地址,就说明配置成功了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值