By default, Linodes use DHCP to acquire their IP address, routing and DNS information. However, DHCP will only assign one IP to your Linode, so if you have multiple IPs you'll need to use a static configuration. Even if you only have one IP, you can still do a static assignment, but it's not necessary.
These instructions work with the Linode platform. If you don't have a Linode yet, sign up for a Linux VPS and get started today.
Before we move on to editing files, we need to gather some information. Log into the Linode Manager and click the Network tab. In the "Network Configuration"" section you'll find your IP addresses (both public & private), gateways, netmasks and DNS servers.
Keep this information handy, because you'll need to refer to it as you do the configuration. Since Linodes only have one virtual ethernet interface (eth0), you'll need to assign each additional IP to an alias on that interface. This means you'll append a colon and a number to the interface name. For our examples, we're just going to number them in the order they were given, but most outbound connections will originate from the IP assigned to the eth0 interface. If you need server daemons to bind to a particular IP address, you'll need to specify the correct IP in their configuration files.
Please note that although your VPS may have multiple IP addresses assigned to it, you should only specify a default gateway for one IP. This gateway should be the one that corresponds to the IP address you are setting it on. For example, if you are setting the default gateway for "12.34.56.78" you should use "12.34.56.1" for the gateway.
A default gateway should not be specified for private IP addresses. Additionally, the subnet mask for private IP addresses should be set to "255.255.128.0" (not "255.255.255.0").
Important: You must reboot your Linode after adding an IP address to it before the changes will take effect.
If you've migrated to a new location, you may need to edit your /etc/resolv.conf file so that your Linode can resolve DNS queries. Your nameservers are listed under the "Network" tab. The search and domain lines are optional, but you should definitely include the options rotate line.
In the example below, change the IP addresses to reflect the values shown under the "Network" tab of the Linode Manager.
File: /etc/resolv.conf
domain members.linode.com search members.linode.com nameserver 98.76.54.32 nameserver 76.54.32.10 options rotate
Change the nameserver IP addresses to reflect the values shown under the "Network" tab of the Linode Manager.
Since Ubuntu is based on Debian, their configuration is the same. The relevant file to edit is /etc/network/interfaces - the file syntax is fairly straightforward, but you can read the comments in the file for more details about what each line does.
In the example below, change the IP addresses to reflect the values shown under the "Network" tab of the Linode Manager.
File: /etc/network/interfaces
# The loopback interface auto lo iface lo inet loopback # Configuration for eth0 and aliases # This line ensures that the interface will be brought up during boot. auto eth0 eth0:0 eth0:1 # eth0 - This is the main IP address that will be used for most outbound connections. # The address, netmask and gateway are all necessary. iface eth0 inet static address 12.34.56.78 netmask 255.255.255.0 gateway 12.34.56.1 # eth0:0 iface eth0:0 inet static address 34.56.78.90 netmask 255.255.255.0 # eth0:1 - Private IPs have no gateway (they are not publicly routable) so all you need to # specify is the address and netmask. iface eth0:1 inet static address 192.168.133.234 netmask 255.255.128.0
Restart networking:
/etc/init.d/networking restart
From the Linode, ping each of the default gateways listed on the "Network" tab of the Linode Manager:
ping 12.34.56.1 ping 98.76.54.1
Note: CentOS & Fedora may include two services to configure and having the wrong one enabled may cause networking to not come up after making these changes. You can check your configuration using these instructions.
CentOS keeps the information for each interface in a separate file named /etc/sysconfig/network-scripts/ifcfg-<interface_name> so you'll need to create one for eth0 and one for each alias.
In the example below, change the IP addresses to reflect the values shown under the "Network" tab of the Linode Manager.
File: /etc/sysconfig/network-scripts/ifcfg-eth0
# Configuration for eth0 DEVICE=eth0 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0 - This is the main IP address that will be used for most outbound connections. # The address, netmask and gateway are all necessary. IPADDR=12.34.56.78 NETMASK=255.255.255.0 GATEWAY=12.34.56.1
File: /etc/sysconfig/network-scripts/ifcfg-eth0:0
# Configuration for eth0:0 DEVICE=eth0:0 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0:0 IPADDR=34.56.78.90 NETMASK=255.255.255.0
File: /etc/sysconfig/network-scripts/ifcfg-eth0:1
# Configuration for eth0:1 DEVICE=eth0:1 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0:1 - Private IPs have no gateway (they are not publicly routable) so all you need to # specify is the address and netmask. IPADDR=192.168.133.234 NETMASK=255.255.128.0
Restart networking:
service network restart
From the Linode, ping each of the default gateways listed on the "Network" tab of the Linode Manager:
ping 12.34.56.1 ping 98.76.54.1
In the example below, change the IP addresses to reflect the values shown under the Network tab of the Linode Manager. All other details should remain the same. The configuration of networking states occurs in the /etc/rc.conf file. Add a hash sign (e.g. #) to the beginning of the existing INTERFACES and eth0 lines to convert them to comments, then add the following lines to your rc.conf file.
File excerpt: /etc/rc.conf
eth0="eth0 12.34.56.78 netmask 255.255.255.0" eth0_0="eth0:0 21.43.65.87 netmask 255.255.255.0" eth0_1="eth0:1 192.168.134.241 netmask 255.255.128.0" INTERFACES=(eth0 eth0_0 eth0_1) gateway="default gw 12.34.56.1" ROUTES=(gateway)
In this example, we configure two static public interfaces on eth0, eth0:0, and eth0:1. Ensure that every interface configuration is included in the INTERFACES list. When you have configured these, issue the following command:
/etc/rc.d/network restart
Due to the way that Arch Linux handles network interfaces, this command will report that the "Stopping the Network Interfaces" operation has failed. When you issue the command ifconfig, you will be able to see the properly configured interfaces.
From the Linode, ping each of the default gateways listed on the "Network" tab of the Linode Manager:
ping 12.34.56.1 ping 98.76.54.1
In the example below, change the IP addresses to reflect the values shown under the "Network" tab of the Linode Manager. You'll be setting up a static public IP on eth0 and a static private IP on eth0:1. We recommend logging into LISH, since you'll be restarting the network.
First, open /etc/conf.d/net and comment your existing config_ethX and routes_ethX lines:
#config_eth0=( "12.34.56.XXX netmask 255.255.255.0" ) #routes_eth0=( "default gw 12.34.56.1" ) #config_eth1=( "192.168.133.XXX netmask 255.255.128.0" )
Using the comments in /etc/conf.d/net.example as your guide, create a new config_eth0 entry that contains both of your addresses in CIDR notation:
config_eth0=(
"12.34.56.XXX/24"
"192.168.133.XXX/17"
)
Tip: Type your netmask here
to
get correct CIDR.
Now add a new routes_eth0 entry:
routes_eth0=( "default via 12.34.56.1" )
Full example of working /etc/conf.d/net:
config_eth0=(
"12.34.56.XXX/24"
"192.168.133.XXX/17"
)
routes_eth0=( "default via 12.34.56.1" )
dns_servers="34.56.78.90 34.56.78.91 34.56.78.92"
dns_search="example.com members.linode.com"
dns_domain="example.com"
Stop your existing eth1 interface and remove it from startup, if applicable:
/etc/init.d/net.eth1 stop rc-update del net.eth1 default rm /etc/init.d/net.eth1
Restart networking:
/etc/init.d/net.eth0 restart
From the Linode, ping each of the default gateways listed on the "Network" tab of the Linode Manager:
ping 12.34.56.1 ping 98.76.54.1
In the example below, change the IP addresses to reflect the values shown under the "Network"" tab of the Linode Manager.
File: /etc/sysconfig/network/ifcfg-eth0
# Configuration for eth0 BOOTPROTO='static' # This line ensures that the interface will be brought up during boot. STARTMODE='onboot' # eth0 - This is the main IP address that will be used for most outbound connections. # The address, netmask and gateway are all necessary. The metric is not necessary but # ensures you always talk to the same gateway if you have multiple public IPs from # different subnets. IPADDR='12.34.56.78' NETMASK='255.255.255.0' # eth0:0 IPADDR1='34.56.78.90' NETMASK1='255.255.255.0' LABEL1='0' # eth0:1 - Private IP IPADDR2='192.168.133.234' NETMASK2='255.255.128.0' LABEL2='1'
Create the following file if necessary:
File: /etc/sysconfig/network/routes
# Destination Gateway Netmask Device 66.246.75.0 0.0.0.0 255.255.255.0 eth0 0.0.0.0 12.34.56.1 0.0.0.0 eth0
Double-check that your /etc/resolv.conf exists and is correct.
Restart networking:
/etc/init.d/network restart
From the Linode, ping each of the default gateways listed on the "Network" tab of the Linode Manager:
ping 12.34.56.1 ping 98.76.54.1
This guide is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License
.
Please feel free to redistribute unmodified copies of it as long as attribution is provided, preferably via a link to this page.
|
|
Submitted by pparadis on Thursday, August 6 2009 at 19:07:24 GMT
@Michael: The IP address for eth0:0 is correct, as it represents a separate interface alias.
|
|
|
Submitted by Nick Hoffman on Wednesday, September 30 2009 at 18:27:35 GMT
eth0 is your Linode's public IP address.
eth0:1 is your Linode's private IP address. What is eth0:0 being used for in this article? |
|
|
Submitted by Kevin Kohrt on Monday, November 9 2009 at 14:02:35 GMT
Just FYI: On Fedora, [system-config-network-tui] (may need to install ...) allows you to generate the recommended centos config files, but does not set [ONBOOT=yes]
|
|
|
Submitted by Phil Paradis on Monday, November 23 2009 at 11:05:49 GMT
@Nick The eth0:0 alias is to illustrate having more than one public IP assigned.
|
|
|
Submitted by Jeff on Monday, January 4 2010 at 07:30:18 GMT
What does the "options rotate" directive in /etc/resolv.conf do?
|
|
|
Submitted by Stan Schwertly on Monday, January 4 2010 at 14:35:01 GMT
@Jeff: The "options rotate" directive spreads the load across the nameservers instead of trying to query the first one listed each time.
|
|
|
Submitted by tim on Wednesday, January 13 2010 at 05:17:31 GMT
So being the n00b that I am I went ahead and added an IP not knowing the impacts. Found things didn't work the way they had before, came here followed the guide and have almost everything corrected. I have one issue still broken...
Prior to adding an IP I was able to use curl. Now I can't. The first error got was that their was no hostname, so I fixed that using you other guide, but now I get: " curl: (6) Couldn't resolve host 'site.com' " I know the site is up and running. It seems my debian linode can't resolve the nameservers to get out? Any ideas? |
|
|
Submitted by Phil Paradis on Thursday, March 25 2010 at 17:48:31 GMT
@tim - You may need to check /etc/resolv.conf to make sure the DNS resolvers listed in the "Network" tab of the Linode Manager are present. If that looks good, check your firewall rules to make sure outbound traffic isn't being blocked.
|
|
|
Submitted by Sean on Thursday, April 8 2010 at 14:40:08 GMT
How about putting a link to this article in the "extras" screen when we add a new IP address?
FWIW, until I read this article it wasn't obvious that: - We have to reboot to get the new IP - You can't use DHCP anymore The second one caused the most problems. I was able to set up the eth0:0 as a static without any documentation, but when I rebooted my linode I was surprised when eth0 picked up my new address! |
|
|
Submitted by Stan Schwertly on Saturday, May 22 2010 at 17:13:38 GMT
That's an excellent suggestion, Sean! I'll forward it to our developers for review.
|
|
|
Submitted by SChirpich on Monday, July 26 2010 at 06:11:35 GMT
Shouldn't this work for Ubuntu 10.04 without a reboot? No matter what I did I couldn't get my second IP to ping out until I eventually gave in and rebooted my Linode.
Am I going crazy or does the documentation need to be updated for Ubuntu? |
|
|
Submitted by Phil Paradis on Tuesday, July 27 2010 at 11:24:34 GMT
@SChirpich - When adding an IP address, all Linodes require a reboot for the new IP to be routed. The installed distribution has no effect on this requirement.
|
Got a comment?