Configure Static IPs
From LinodeWiki
Contents |
[edit] Linode Library
|
Please see the article in the Linode Library on Configuring Static IPs for more information and additional resources. |
[edit] Static IP Configuration
By default, Linodes use DHCP to acquire their IP address, routing and DNS information. DHCP, however, 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.
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. Please note: If you have just purchased your second IP Address, you will need to reboot your Linode before these network changes will take effect.
Keep this info handy, because you'll need to refer to it as you do the configuration. Since Linodes only have one virtual Ethernet interface--eth0--we're going to assign each IP to an alias on that interface. This just means we append a colon and a number to the interface name. For our example we're just going to number them in the order they were given, but most outbound connections will originate from the IP assigned the eth0 interface so you may want to shuffle yours around depending on your own needs.
The table below shows the IPs assigned to our example Linode and the interfaces we're going to bind them to in the example configurations:
| IP Address | Public | Netmask | Gateway | Interface |
|---|---|---|---|---|
| 66.246.75.77 | Yes | 255.255.255.0 | 66.246.75.1 | eth0 |
| 97.107.130.169 | Yes | 255.255.255.0 | 97.107.130.1 | eth0:0 |
| 192.168.133.234 | No | 255.255.128.0 | None | eth0:1 |
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.
File: /etc/resolv.conf
domain members.linode.com search members.linode.com nameserver 123.123.78.9 nameserver 123.123.78.10 options rotate
[edit] Debian & Ubuntu
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.
/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 66.246.75.77 netmask 255.255.255.0 gateway 66.246.75.1 # eth0:0 iface eth0:0 inet static address 97.107.130.169 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
[edit] CentOS & Fedora
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.
/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=66.246.75.77 NETMASK=255.255.255.0 BROADCAST=66.246.75.255 GATEWAY=66.246.75.1
/etc/sysconfig/network-scripts/ifcfg-eth0:0
# Configuration for eth0:0 DEVICE=eth0:0 BOOTPROTO=none # This line ensures that the alias will be brought up when the interface is. ONPARENT=yes # eth0:0 IPADDR=97.107.130.169 NETMASK=255.255.255.0 BROADCAST=97.107.130.255 GATEWAY=97.107.130.1
/etc/sysconfig/network-scripts/ifcfg-eth0:1
# Configuration for eth0:1 DEVICE=eth0:1 BOOTPROTO=none # This line ensures that the alias will be brought up when the interface is. ONPARENT=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 BROADCAST=192.168.133.255
[edit] Gentoo
How to configure a static public IP on eth0 and a static private IP on eth0:1.
Overview
- Login to LISH (ssh not recommended since you'll be restarting network)
- Configure /etc/conf.d/net
- /etc/init.d/net.eth1 stop
- rc-update del net.eth1 default
- rm /etc/init.d/net.eth1
- /etc/init.d/net.eth0 restart
Detailed Steps
Open /etc/conf.d/net and comment your existing config_ethX and routes_ethX lines:
#config_eth0=( "207.192.69.XXX netmask 255.255.255.0" ) #routes_eth0=( "default gw 207.192.69.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=(
"207.192.69.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 207.192.69.1" )
Full example of working /etc/conf.d/net:
config_eth0=(
"207.192.69.XXX/24"
"192.168.133.XXX/17"
)
routes_eth0=( "default via 207.192.69.1" )
dns_servers="207.192.69.4 207.192.69.5 67.18.92.50"
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 eth0:
/etc/init.d/net.eth0 restart
[edit] OpenSUSE
/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='66.246.75.77' NETMASK='255.255.255.0' # eth0:0 IPADDR1='97.107.130.169' NETMASK1='255.255.255.0' LABEL1='0' # eth0:1 - Private IP IPADDR2='192.168.133.234' NETMASK2='255.255.128.0' LABEL2='1'
Create if neccessary:
/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 66.246.75.1 0.0.0.0 eth0
Double-check your /etc/resolv.conf exists and is correct.
Restart eth0:
/etc/init.d/network restart
