Linux 系统配合多个网口IP,Linux系统添加绑定多IP和IP段的方法

Centos:

一、先用命令查看网卡设备名称,执行命令后会返回网卡接口信息,再看要绑定哪一个接口。

[root@localhost ]# ip link | awk 'NR%2==1' | awk '{print $2,$8,$9}' | tr -d ':'

二、用以下命令查看所有网卡接口配置文件,留意ifcfg开头的文件

/etc/sysconfig/network-scripts/

三、配置内容一般就是以下这些,这里可以设置默认DNS地址、IP4地址、IP6地址,IPADDR=这里多个地址以半角状态下的逗号,分隔开多个IP地址。

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=enp3s0

UUID=a007fd6d-4cc5-45b6-9a38-991a8e820eaf

DEVICE=enp3s0

ONBOOT=yes

IPADDR=10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6

PREFIX=29

GATEWAY=10.0.0.1

DNS1=8.8.8.8

DNS2=8.8.4.4

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

BOOTPROTO=static

DEVICE=eth0

IPADDR0=IP0

NETMASK0=子网掩码

IPADDR1=IP1

NETMASK1=子网掩码

IPADDR2=IP2

NETMASK2=子网掩码

GATEWAY=网关

NM_CONTROLLED=no

ONBOOT=yes

TYPE=Ethernet

USERCTL=no

PERSISTENT_DHCLIENT=yes

四、将以下文本附加到文件的末尾并保存: NM_CONTROLLED=NO

systemctl restart network.service

service network restart

五、另外的方法

If you own 192.168.125.0/24, and you need to add all of the IP's in that range, we can add it like the following:

Create a file '/etc/sysconfig/network-scripts/ifcfg-eth0-range0' based on which ethernet card you are using.

vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

Add the following lines in the file:

IPADDR_START=192.168.125.3

IPADDR_END=192.168.125.254

NETMASK=255.255.255.255

CLONENUM_START=1

Here you need to replace the start IP and end IP based on what you own.

If you needed to add first 100 IP's only, you can set the first IP as 192.168.125.3 and end IP as 192.168.125.102. But make sure that any IP's in between these are not used somewhere else.

3. Once the configuration is added you can restart the network service or reboot the server. It is better to have IPMI access before doing such changes.

Debian

编辑 /etc/network/interfaces 添加上你的新IP,

假设你原有IP为 11.11.11.11,想要添加 22.22.22.22 和 33.33.33.33 新IP,按以下样例修改:

auto lo iface lo inet loopback

auto eth0 iface eth0 inet static address 11.11.11.11 netmask 255.255.255.0 gateway 11.11.11.1

auto eth0:0 iface eth0:0 inet static address 22.22.22.22 netmask 255.255.255.0

auto eth0:1 iface eth0:1 inet static address 33.33.33.33 netmask 255.255.255.0

就是只要按着顺序添加 eth0:0 , eth0:1 , eth0:X 一直加下去

修改之后,/etc/init.d/networking restart 重启网络,

另需要将新IP上线,ifup eth0:0 有多个IP,就按顺序 ifup eth0:1 ifup eth0:2 ifup eth0:3 ifup eth0:x ….

a21779c7f0970367c54c83e355e464d5.png

sicnature ---------------------------------------------------------------------

Your current IP address is: 113.206.128.68

Your IP address location: 重庆市联通

Your IP address country and region: 中国

d9840db1de5c066b3143a36b83ba0940.png

Your current browser is:

c55e3eff36f0c380a04e3e5ffee3bbca.png

Your current system is:

mac.png

Original content, please indicate the source:

同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog

sicnature ---------------------------------------------------------------------

Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/3218.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值