Change

Before migrating IP addresses, make sure to read the static networking guide to learn how configuration is performed.

Suppose your old IPv4 address is 192.168.1.2, and your new IPv4 address is 10.0.1.3. The old default gateway was 192.168.1.1 with subnet mask 255.255.255.0. The new default gateway is 10.0.0.1, with subnet mask 255.255.255.0. Your old IPv6 address is 2001:db8:1::1, and your new IPv6 address is 2001:db8:2::2. The default gateway remains the same, 2001:db8::1, with prefix length 48.

 OldNew
IPv4192.168.1.210.0.1.3
Default Gateway192.168.1.110.0.0.1
Subnet Mask255.255.255.0 or 0xffffff00255.255.255.128 or 0xffffff80
IPv62001:db8:1::12001:db8:2::2
Default Gateway2001:db8::12001:db8::1
Prefix Length4848

Configuring /etc/hostname.if

First you will need to configure your hostname.if configuration file. If you have a virtio network device, edit /etc/hostname.vio0 to the following:

inet 10.0.1.3 0xffffff80
inet alias 192.168.1.2 0xffffffff
inet6 2001:db8:2::2 48
inet6 alias 2001:db8:1::1 48

The first line configures the IP addresses, 10.0.1.3. The subnet mask here could be written as either 255.255.255.128 (in dotted quad notation) or as 0xffffff80 (in hexadecimal notation). They are both equivalent.

The second line creates an aliased IP address 192.168.1.2. This will allow your VPS to use either IP address. The subnet mask here should be set to 0xffffffff or 255.255.255.255 because it's an aliased IP address.

The third line configures the IPv6 address 2001:db8:2::2 with a prefix length of 48. The fourth line configures the alias 2001:db8:1::1, with a prefix length of 48.

Configuring /etc/mygate

You will next need to update your default gateway:

10.0.0.1
2001:db8::1

Restarting networking

Disable the network interface, flush old routes, then restart networking:

WARNING: This step will cause network disconnections. If any files are misconfigured, you may not be able to reconnect. Make sure you have serial console access before proceeding:

$ doas ifconfig vio0 down && doas route flush && doas sh /etc/netstart

Stale hostname

If you change your host's IP address, double check /etc/hosts to ensure there are no old, stale values that could intercept name lookup.

Test New IP Adddress

After adding an IP address, make sure to test it using ping, netcat, and traceroute?.

For example:

$ ping -I 10.0.1.3 8.8.8.8
$ ping6 -I 2001:db8:2::2 2607:f8b0:400a:80a::200e

If after waiting 30 seconds, ping shows 100% packet loss, then networking has failed.

Other Network Services

ActionDescription
Static NetworkingUpdate ifconfig, /etc/mygate, and /etc/hostname.if0
NSDUpdate the IP addresses in nsd.conf, and update records in zone files
ZNCUpdate the IP addresses in znc.conf's listeners
ngircdUpdate the Listen = IP addresses in ngircd.conf
UnboundUpdate the outgoing-interfaces in unbound.conf
RelaydUpdate IP addresses in relayd.conf
Packet FilterUpdate Packet Filter
PingTroubleshoot networking using ping
NetcatTroubleshoot networking using netcat