OpenBSD, dynamic and static IP address on the same interface
0 Comments Published by Felipe Alfaro Solana May 8th, 2009 in DHCP, OpenBSDToday I was faced with the following problem: I was trying to configure one of the Ethernet interfaces of an OpenBSD 4.5 box with both a dynamic address leased via DHCP, but also a static IP address. Initially, I tried this:
# cat /etc/hostname.vr2 dhcp inet 1.1.1.11 255.255.255.0 NONE up # sh /etc/netstart vr2
The problem with this approach is that dhclient never gets daemonized because netstart gets it annoyed: dhclient notices that something else reconfigured the interface and commits suicide. So, then I thought about reversing the order of the first two lines:
# cat /etc/hostname.vr2 inet 1.1.1.11 255.255.255.0 NONE dhcp up # sh /etc/netstart vr2
Now dhclient daemonizes but also removes all previously configured IP addresses, so the statically configured address configured via the first line is wiped by dhclient. Not very nice.
Turns out the solution lies in /etc/dhclient.conf:
# cat /etc/dhclient.conf
interface "vr2" {
supersede domain-name "example.com";
supersede domain-name-servers 1.1.1.1;
}
alias {
interface "vr2";
fixed-address 1.1.1.11;
option subnet-mask 255.255.255.0;
}
The alias stanza allows one to define an additional, aliased IP address for an interface. Which allows the machine to be always reachable on a fixed IP address.
Neat.
No Comments to “OpenBSD, dynamic and static IP address on the same interface”
Please Wait
Leave a Reply