Guides - Network Configuration Using ifupdown
Linux virtual machines equipped with a tailored set of resources designed to run any cloud-based workload.
The ifupdown package is an older network configuration software that’s still used by Debian and older Ubuntu distributions (such as 16.04 LTS and earlier).
Configuration Files
Network configuration settings for ifupdown are managed inside of an interfaces file or series of files. The main configuration is typically stored in /etc/network/interfaces
and additional files are typically added within /etc/network/interfaces.d/*
- Default configuration file:
/etc/network/interfaces
Starter Configuration
Here is an example of a typical configuration file for ifupdown. It statically defines the IPv4 address and allows SLAAC to configure the IPv6 address.
- File: /etc/network/interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13
auto lo iface lo inet loopback source /etc/network/interfaces.d/* auto eth0 allow-hotplug eth0 iface eth0 inet6 auto iface eth0 inet static address 192.0.2.123/24 gateway 192.0.2.1
Configuring IP Addresses Manually
Log in to the Cloud Manager and review your Compute Instance’s IP addresses. See Managing IP Addresses. Make a note of the following pieces of information or keep this page accessible so you can reference it later.
- Public IPv4 address(es) and the associated IPv4 gateway
- Private IPv4 address (if one has been added)
- IPv6 SLAAC address and the associated IPv6 gateway
- IPv6 /64 or /56 routed range (if one has been added)
- DNS resolvers (if you want to use Linode’s resolvers)
Disable Network Helper on the Compute Instance so that it doesn’t overwrite any of your changes on the next system reboot. For instructions, see the Network Helper guide. This guide covers disabling Network Helper globally (for all Compute Instances on your account) or just for a single instance.
Log in to the Compute Instance using SSH or Lish. You may want to consider using Lish to avoid getting locked out in the case of a configuration error.
Perform any necessary configuration steps as outlined in the workflows below. You can edit your network configuration file using a text editor like nano or vim.
sudo nano /etc/network/interfaces
Once you’ve edited the configuration file to fit your needs, you need to apply the changes or reboot the Compute Instance. To apply your changes with ifupdown, run the following commands:
sudo ifdown eth0 && sudo ip addr flush eth0 && sudo ifup eth0
Changing the Primary IPv4 Address
To change the main IPv4 address configured on the system, set the address
and gateway
parameters under iface eth0 inet static
to match the new IP address and its corresponding gateway IP address.
- File: /etc/network/interfaces
1 2 3 4
... iface eth0 inet static address 192.0.2.123/24 gateway 192.0.2.1
Configuring the Primary IPv4 Address through DHCP
DHCP can be used to automatically configure your primary IPv4 address. The primary IPv4 address is defined as the IPv4 address assigned to your system that is in the first position when sorted numerically. To enable DHCP, modify or add an iface
for your interface using dhcp
instead of static
.
- File: /etc/network/interfaces
1 2 3 4 5
... iface eth0 inet dhcp # iface eth0 inet static # address 192.0.2.123/24 # gateway 192.0.2.1
To disable DHCP, switch dhcp
back to static
and manually add the relevant address
and gateway
lines.
Configuring Additional IPv4 Addresses
Additional IP addresses can be configured by adding or modifying the iface
group for the desired interface. Multiple address
lines can be provided to configure more than one IP address.
- File: /etc/network/interfaces
1 2 3
... iface eth0 inet static address [ip-address]/[prefix]
In the example above, make the following replacements:
- [ip-address]: The IPv4 address that you wish to statically configure.
- [prefix]: The prefix is based on the type of IP address you are adding. It should be
24
for public IPv4 addresses and17
for private IPv4 addresses.
Configuring the Primary IPv6 Address through SLAAC
SLAAC is used to automatically configure your primary IPv6 address. Within ifupdown, you can configure an IPv6 SLAAC address by adding or modifying the iface
for your interface and the inet6
protocol, making sure to set it to auto
instead of static
.
- File: /etc/network/interfaces
1 2 3
... iface eth0 inet6 auto accept_ra 2
If you wish to disable IPv6 SLAAC addressing and instead statically configure your primary IPv6 address (not recommended), you can modify the iface eth0 inet6
group by setting it to static
and adding your primary IPv6 address within the address
parameter (using the prefix of /128
).
- File: /etc/network/interfaces
1 2 3 4
... iface eth0 inet6 static address [ip-address]/128 # accept_ra 2
Configuring Additional IPv6 Addresses
If you have an IPv6 range assigned to your Compute Instance, addresses from this range can be configured within the iface eth0 inet6
group, making sure it’s set to static
instead of auto
. Multiple address
lines can be provided to configure more than one IP address.
- File: /etc/network/interfaces
1 2 3 4 5
... iface eth0 inet6 static address [ip-address]/[prefix] autoconf 1 accept_ra 2
In the example above, make the following replacements:
- [ip-address]: The IPv6 address that you wish to statically configure. You can choose any address within your available range. For example, within the range 2001:db8:e001:1b8c::/64, the address
2001:db8:e001:1b8c::1
can be used. - [prefix]: The prefix should either be
64
or56
(depending on the size of your IPv6 range).
The autoconf
parameter (when set to 1
), allows the primary IPv6 address to be automatically configured through SLAAC, which is the preferred behavior for most cases.
Changing the DNS Resolvers
DNS resolvers are the entities that resolve domain names to their corresponding IPv4 address. By default, the Compute Instance should be using the DNS resolvers for the data center in which it resides. You can change these through the /etc/resolv.conf
file, setting the nameserver
parameters to your preferred DNS resolvers.
- File: /etc/resolv.conf
1 2 3 4 5 6
domain ip.linodeusercontent.com search ip.linodeusercontent.com nameserver 203.0.113.1 nameserver 203.0.113.2 nameserver 203.0.113.3 ...
In the above example, replace the IP addresses provided with the IP addresses of the DNS resolvers you wish to use.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on