因业务需要。freebsd服务器在同一网卡下需要添加多个ip地址。登陆到服务器
使用ifconfig 命令。
ifconfig {interface} {ip_addr_alias} netmask 255.255.255.255 alias
如:
# ifconfig rl0 192.168.1.5 netmask 255.255.255.0 alias
# ifconfig
rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=8<VLAN_MTU>
inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
inet 192.168.1.5 netmask 0xffffff00 broadcast 192.168.1.255
ether 00:e0:4c:8c:59:75
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
# ifconfig
rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=8<VLAN_MTU>
inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
inet 192.168.1.5 netmask 0xffffff00 broadcast 192.168.1.255
ether 00:e0:4c:8c:59:75
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
要去掉 alias : (就是把最后改为 -alias)
ifconfig {interface} {ip_addr_alias} netmask 255.255.255.255 -alias
ifconfig {interface} {ip_addr_alias} netmask 255.255.255.255 -alias
如:
# ifconfig rl0 192.168.1.5 netmask 255.255.255.255 -alias
# ifconfig
rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=8<VLAN_MTU>
inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
ether 00:e0:4c:8c:59:75
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
# ifconfig
rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=8<VLAN_MTU>
inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
ether 00:e0:4c:8c:59:75
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
要想在开机时就自动设定IP Alias,需要在/etc/rc.conf下加入:
ifconfig_rl0_ alias0="inet xxx.xxx.xxx.xxx netmask 255.255.255.xxx"
^^^ ^^^^^^^^^^^^^^^
网络接口名称 这里是你希望使用的IP地址。
通过这种方式你可以给一块网卡设定很多IP地址。
转载于:https://blog.51cto.com/qingwang/110384