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.
Old | New | |
---|---|---|
IPv4 | 192.168.1.2 | 10.0.1.3 |
Default Gateway | 192.168.1.1 | 10.0.0.1 |
Subnet Mask | 255.255.255.0 or 0xffffff00 | 255.255.255.128 or 0xffffff80 |
IPv6 | 2001:db8:1::1 | 2001:db8:2::2 |
Default Gateway | 2001:db8::1 | 2001:db8::1 |
Prefix Length | 48 | 48 |
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
Action | Description |
---|---|
Static Networking | Update ifconfig, /etc/mygate, and /etc/hostname.if0 |
NSD | Update the IP addresses in nsd.conf, and update records in zone files |
ZNC | Update the IP addresses in znc.conf's listeners |
ngircd | Update the Listen = IP addresses in ngircd.conf |
Unbound | Update the outgoing-interfaces in unbound.conf |
Relayd | Update IP addresses in relayd.conf |
Packet Filter | Update Packet Filter |
Ping | Troubleshoot networking using ping |
Netcat | Troubleshoot networking using netcat |