ubuntu 16 添加多个IP

多个不同IP段的 /etc/network/interfaces 配置文件的范例如下:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 8.8.8.2
netmask 255.255.255.248
gateway 8.8.8.1 要注意这里,多个不同IP段,只要1个gateway配置即可,其他IP不需要配置gateway
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0:0
iface eth0:0 inet static
address 8.8.8.3
netmask 255.255.255.248
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0:1
iface eth0:1 inet static
address 8.8.8.4
netmask 255.255.255.248
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0:2
iface eth0:2 inet static
address 8.8.8.5
netmask 255.255.255.248
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0:3
iface eth0:3 inet static
address 8.8.8.6
netmask 255.255.255.248
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0:4
iface eth0:4 inet static
address 6.6.6.130 注意这里,虽然这是不同的IP段,但是不需要配置gateway,只需要配置netmask即可
netmask 255.255.255.224
dns-nameservers 8.8.8.8 8.8.4.4

 

更多ip也类似配置即可。

配置文件完成后,用命令 /etc/init.d/networking restart /reload重启网络

 转载于:https://www.cnblogs.com/qunshu/p/3236807.html

posted @   小流亡  阅读(1428)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示