简洁的想法

 找回密码
 注册
搜索
查看: 1151|回复: 1

IP Alias - linux中单网卡多IP

[复制链接]
发表于 2007-5-22 12:44:26 | 显示全部楼层 |阅读模式
可以运行命令ifconfig 添加IP Alias

在eth0:0上添加IP地址192.168.0.128/255.255.255.0
  1. # ifconfig eth0:0 192.168.0.128netmask 255.255.255.0 up
复制代码


删除IP Alias eth0:0
  1. # ifconfig eth0:0 down
复制代码



为一块网卡配置多IP可以通过命令行设置也可以通过配置文件设置,以下我分别通过这两种方式实现:

1.用命令行设置

  1. ifconfig命令格式:ifconfig 设备名 IP netmask 掩码 broadcast 广播地址 动作
复制代码


# ifconfig
  1. eth0 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  2. inet addr:192.168.16.108 Bcast:192.168.16.255 Mask:255.255.255.0
  3. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  4. RX packets:2 errors:0 dropped:0 overruns:0 frame:0
  5. TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
  6. collisions:0 txqueuelen:100
  7. RX bytes:224 (224.0 b) TX bytes:387 (387.0 b)
  8. Interrupt:11 Base address:0x2000

  9. lo Link encap:Local Loopback
  10. inet addr:127.0.0.1 Mask:255.0.0.0
  11. UP LOOPBACK RUNNING MTU:16436 Metric:1
  12. RX packets:773 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:773 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:0
  15. RX bytes:52352 (51.1 Kb) TX bytes:52352 (51.1 Kb)
复制代码


可以看到,当前eth0的IP为192.168.16.108,此时请注意一下MAC(00:0E:1F:01:6C:50)

现在我们为eth0绑定另一个IP,设备为eth0:0,可以看到,现在又多了一个IP,注意,网卡实际上只有一块(可以看MAC,都为00:0E:1F:01:6C:50),却绑定了两个IP,可以依此配置多个IP。
  1. # ifconfig eth0:0 192.168.1.100 netmask 255.255.255.0
复制代码

# ifconfig
  1. eth0 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  2. inet addr:192.168.16.108 Bcast:192.168.16.255 Mask:255.255.255.0
  3. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  4. RX packets:29 errors:0 dropped:0 overruns:0 frame:0
  5. TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
  6. collisions:0 txqueuelen:100
  7. RX bytes:2879 (2.8 Kb) TX bytes:387 (387.0 b)
  8. Interrupt:11 Base address:0x2000

  9. eth0:0 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  10. inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
  11. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  12. RX packets:29 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:100
  15. RX bytes:2879 (2.8 Kb) TX bytes:387 (387.0 b)
  16. Interrupt:11 Base address:0x2000

  17. lo Link encap:Local Loopback
  18. inet addr:127.0.0.1 Mask:255.0.0.0
  19. UP LOOPBACK RUNNING MTU:16436 Metric:1
  20. RX packets:7329 errors:0 dropped:0 overruns:0 frame:0
  21. TX packets:7329 errors:0 dropped:0 overruns:0 carrier:0
  22. collisions:0 txqueuelen:0
  23. RX bytes:500674 (488.9 Kb) TX bytes:500674 (488.9 Kb)
复制代码


2.通过配置文件设置多IP
网卡IP配置的文件在/etc/sysconfig/network-scripts/下,文件分别为ehtx或ethx:x
# cd /etc/sysconfig/network-scripts/
# ls


ifcfg-eth0 ifdown-ippp ifdown-ppp ifup-aliases ifup-isdn ifup-ppp ifup-wireless
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-ippp ifup-plip ifup-routes init.ipv6-global
ifdown ifdown-isdn ifdown-sl ifup-ipv6 ifup-plusb ifup-sit network-functions
ifdown-aliases ifdown-post ifup ifup-ipx ifup-post ifup-sl network-functions-ipv6

#这是eth0的对应的内容
#vi ifcfg-eth0
  1. DEVICE=eth0
  2. BOOTPROTO=none
  3. ONBOOT=yes
  4. USERCTL=no
  5. PEERDNS=yes
  6. TYPE=Ethernet
  7. IPADDR=192.168.16.108
  8. NETMASK=255.255.255.0
  9. HWADDR=00:0e:1f:01:6c:50
  10. GATEWAY=192.168.16.1
  11. NETWORK=192.168.16.0
  12. BROADCAST=192.168.16.255
复制代码


配置另一IP,因我们刚才已配置了eth0:0,所以此时要用eth0:1了
# cp ifcfg-eth0 ifcfg-eth0:1
修改配置文件,内容如下
# vi ifcfg-eth0:1
  1. DEVICE=eth0:1
  2. ONBOOT=yes
  3. BOOTPROTO=static
  4. IPADDR=192.168.2.100
  5. NETMASK=255.255.255.0
  6. NETWORK=192.168.2.0
复制代码


启动eth0:1,查看,此时是不是就已经有三个IP了?
# ifup eth0:1
# ifconfig

  1. eth0 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  2. inet addr:192.168.16.108 Bcast:192.168.16.255 Mask:255.255.255.0
  3. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  4. RX packets:52 errors:0 dropped:0 overruns:0 frame:0
  5. TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
  6. collisions:0 txqueuelen:100
  7. RX bytes:6037 (5.8 Kb) TX bytes:627 (627.0 b)
  8. Interrupt:11 Base address:0x2000

  9. eth0:0 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  10. inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
  11. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  12. RX packets:52 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:100
  15. RX bytes:6037 (5.8 Kb) TX bytes:627 (627.0 b)
  16. Interrupt:11 Base address:0x2000

  17. eth0:1 Link encap:Ethernet HWaddr 00:0E:1F:01:6C:50
  18. inet addr:192.168.2.100 Bcast:192.168.2.255 Mask:255.255.255.0
  19. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  20. RX packets:52 errors:0 dropped:0 overruns:0 frame:0
  21. TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
  22. collisions:0 txqueuelen:100
  23. RX bytes:6037 (5.8 Kb) TX bytes:627 (627.0 b)
  24. Interrupt:11 Base address:0x2000

  25. lo Link encap:Local Loopback
  26. inet addr:127.0.0.1 Mask:255.0.0.0
  27. UP LOOPBACK RUNNING MTU:16436 Metric:1
  28. RX packets:14131 errors:0 dropped:0 overruns:0 frame:0
  29. TX packets:14131 errors:0 dropped:0 overruns:0 carrier:0
  30. collisions:0 txqueuelen:0
  31. RX bytes:965895 (943.2 Kb) TX bytes:965895 (943.2 Kb)
复制代码


OK,配置成功,这个随便你用哪种方法都可以,用配置文件的方法可以写一些注释,而用ifconfig则简单方便,这就看你的爱好了。

转自:Linux教程-红旗.Redhat操作系统命令学习
 楼主| 发表于 2007-11-19 20:43:16 | 显示全部楼层

SUSE

  1. BOOTPROTO='static'
  2. BROADCAST='85.215.229.255'
  3. IPADDR='85.215.229.81'
  4. MTU=''
  5. NAME='Fujitsu Siemens RTL-8169 Gigabit Ethernet'
  6. NETMASK='255.255.255.0'
  7. NETWORK='85.215.229.0'
  8. REMOTE_IPADDR=''
  9. STARTMODE='onboot'
  10. UNIQUE='rBUF.8HDSqWy46e1'
  11. USERCONTROL='no'
  12. _nm_name='bus-pci-0000:00:09.0'
  13. IPADDR_AAA='85.125.254.245'
  14. BROADCAST_AAA='85.125.254.255'
  15. NETMASK_AAA='255.255.255.0'
  16. NETWORK_AAA='85.125.254.0'
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|Archiver|简洁的想法

GMT+1, 2021-4-19 00:44

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表