Add and Remove ip alias into OpenBSD System
December 5th, 2008
Powered by Max Banner Ads
Set an IP Alias
To put a second IP address to the same interface, just enter on the commandline as root:
OpenBSD# ifconfig re0 inet alias 192.168.10.199 netmask 255.255.255.0
This sets an IP address 192.168.10.199 to vr0. Check again with ifconfig:
OpenBSD# ifconfig -A
lo0: flags=8049 mtu 33208
groups: lo
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
re0: flags=8843 mtu 1500
lladdr 00:40:45:28:89:37
groups: egress
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 192.168.1.199 netmask 0xffffff00 broadcast 192.168.1.255
inet6 fe80::240:45ff:fe28:8937%vr0 prefixlen 64 scopeid 0x2
inet 192.168.10.199 netmask 0xffffff00 broadcast 192.168.100.255
Now we see two IP addresses on vr0. If you want to set an IP address within the same network you would have to set a fake netmask of 255.255.255.255.
Make the IP Alias Permanent
If you use ifconfig to set an IP alias, the alias won’t be present after the next reboot. To make the setting permanent, add a line to /etc/hostname.<INTERFACE>:
OpenBSD# vi /etc/hostname.vr0
inet 192.168.1.199 255.255.255.0 NONE
inet alias 192.168.10.199 255.255.255.0
Remove an IP Alias
You can remove an IP alias with a comand like this:
OpenBSD# ifconfig re0 192.168.10.199 delete
This deletes the second IP address from the interface keeping the first.
