Hello! 欢迎来到小浪云!


linux 云主机系统添加和删除IP,批量添加IP


avatar
小浪云 2024-06-20 42


首先输入root,密码进入

再查看IP网卡,命令ifconfig

xinknat# ifconfig

显示:

eth0      Link encap:Ethernet  HWaddr 00:30:18:A1:A9:4A
          inet addr:98.126.33.66  Bcast:98.126.33.71  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:92139669 errors:0 dropped:0 overruns:0 frame:0
          TX packets:99505579 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3484683143 (3.2 GiB)  TX bytes:476753694 (454.6 MiB)
          interrupt:30 Base address:0xe000

eth0:0    Link encap:Ethernet  HWaddr 00:30:18:A1:A9:4A
          inet addr:98.126.33.67  Bcast:98.126.33.71  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:30 Base address:0xe000

eth0:1    Link encap:Ethernet  HWaddr 00:30:18:A1:A9:4A
          inet addr:98.126.33.68  Bcast:98.126.33.71  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:30 Base address:0xe000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:38 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2068 (2.0 KiB)  TX bytes:2068 (2.0 KiB)

输入:”  ifconfig eth0:2 98.126.33.69 netmask 255.255.255.248 up “

再输入:“vi /etc/sysconfig/network-scripts/ifcfg-eth0:2  “

DEVICE=eth0:2
ONBOOT=yes 
BOOTPROTO=static
ipadDR=98.126.33.69

保存,按Esc退出,输入” : wq “在输入”shift+! “然后回车成功。

 重启网络让IP生效: service network restart

cat /etc/sysconfig/network-scripts/eth0:2    查看更改生效了不

附删除ip方法 
代码: 
ifconfig eth0:2 98.126.33.69 netmask 255.255.255.248 down 
rm /etc/sysconfig/network-scripts/ifcfg-eth0:2

 ————————————

1.添加虚拟ip

    ifconfig eht0:1 192.168.100.22 netmask 255.255.255.0

    2. 删除刚才添加的虚拟IP 

    ip addr del 192.168.100.22/24 dev eth0

————————————————–

单网卡批量添加不同IP段

70.39.112.194 添加IP:70.39.112.195-222/70.39.83.226-254

代码: 

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

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

ipadDR_START=70.39.112.195

ipadDR_END=70.39.112.222

CLONENUM_START=0

GATEWAY=70.39.112.193

NETMASK=255.255.255.224

NO_ALIASROUTING=yes

service network restart  #重启网卡

————————————————————-

ifconfig 后 看到 IP:70.39.112.195-222 对应网卡号:eth0:0-eth0:27,

所以再批量添加IP,网卡从eth0:28以后开始就行,

网卡eth0不变,创建新文件:ifcfg-eth0-range1

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

ipadDR_START=70.39.83.226

ipadDR_END=70.39.83.254

CLONENUM_START=28

GATEWAY=70.39.83.225

NETMASK=255.255.255.224

NO_ALIASROUTING=yes

重启网络让IP生效: service network restart

相关阅读