Published: Thursday, July 16th, 2009 by Phil Paradis
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 required in most cases.
Contents
Before you edit any files, you'll need to obtain some information. Log into the Linode Manager and click the "Remote Access" tab. You'll find your IP addresses (both public and private, if you have a private IP assigned), gateways, netmasks and DNS resolvers. Keep this information handy, because you'll need to refer to it as you configure your Linode's network settings. Since Linodes only have one virtual ethernet interface (eth0), you'll need to assign additional IPs to aliases on that interface. This means you'll append a colon and a number to the interface name. For these examples, the aliases are numbered 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 haven't already done so, set your system's hostname and FQDN (fully qualified domain name). Your hostname should be something unique; some people name their systems after planets, others after philosophers, etc. Please note that the system's hostname has no relationship to websites or email services hosted on it, aside from providing a name for the system itself. Thus, your hostname should not be "www" or anything else too generic. Issue the following commands to set the hostname, replacing "plato" with the hostname of your choice: If it exists, edit the file /etc/default/dhcpcd to comment out the "SET_HOSTNAME" directive: File excerpt:/etc/default/dhcpcd Proceed to the section entitled "Update /etc/hosts" to continue. Issue the following commands to set the hostname, replacing "plato" with the hostname of your choice: Proceed to the section entitled "Update /etc/hosts" to continue. Issue the following commands to set the hostname, replacing "plato" with the hostname of your choice: Proceed to the section entitled "Update /etc/hosts" to continue. Issue the following commands to set the hostname, replacing "plato" with the hostname of your choice: Proceed to the section entitled "Update /etc/hosts" to continue. Issue the following commands to set the hostname, replacing "plato" with the hostname of your choice: Proceed to the section entitled "Update /etc/hosts" to continue. Next, edit your /etc/hosts file to resemble the following example, replacing "plato" with your chosen hostname, "example.com" with your system's domain name, and "12.34.56.78" with your system's IP address. As with the hostname, the domain name part of your FQDN does not necesarily need to have any relationship to websites or other services hosted on the server (although it may if you wish). As an example, you might host "www.something.com" on your server, but the system's FQDN might be "mars.somethingelse.com." File:/etc/hosts The value you assign as your system's FQDN should have an "A" record in DNS pointing to your Linode's IP address. For more information on configuring DNS, please see our guide on configuring DNS with the Linode Manager. 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 "Remote Access" 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 "Remote Access" tab of the Linode Manager. File:/etc/resolv.conf 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 "Remote Access" tab of the Linode Manager. File:/etc/network/interfaces Restart networking: From the Linode, ping each of the default gateways listed on the "Remote Access" tab of the Linode Manager: Once you have confirmed that your networking settings have been correctly configured, issue the following command to uninstall the DHCP client, as it is no longer required. Note: CentOS & Fedora may include two services to configure networking, 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_alias_name> so you'll need to create one foreth0 and one for each alias. In the example below, change the IP addresses to reflect the values shown under the "Remote Access" tab of the Linode Manager. File:/etc/sysconfig/network-scripts/ifcfg-eth0 File:/etc/sysconfig/network-scripts/ifcfg-eth0:0 File:/etc/sysconfig/network-scripts/ifcfg-eth0:1 Restart networking: From the Linode, ping each of the default gateways listed on the "Remote Access" tab of the Linode Manager: In the example below, change the IP addresses to reflect the values shown under the "Remote Access" 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 In this example, two static public IP addresses are configured on aliases of 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: 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 commandifconfig, you will be able to see the properly configured interfaces. From the Linode, ping each of the default gateways listed on the "Remote Access" tab of the Linode Manager: In the example below, change the IP addresses to reflect the values shown under the "Remote Access" 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 out your existing config_ethX and routes_ethX lines: 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: Tip: You can use the free whatmask online tool to get the correct CIDR entry for your netmask. Now add a new routes_eth0 entry: Full example of working /etc/conf.d/net: Stop your existing eth1 interface and remove it from startup, if applicable: Restart networking: From the Linode, ping each of the default gateways listed on the "Remote Access" tab of the Linode Manager: In the example below, change the IP addresses to reflect the values shown under the "Remote Access" tab of the Linode Manager. File:/etc/sysconfig/network/ifcfg-eth0 Create the following file if necessary: File: /etc/sysconfig/network/routes Double-check that your /etc/resolv.conf exists and is correct. Restart networking: From the Linode, ping each of the default gateways listed on the "Remote Access" tab of the Linode Manager:Obtain Networking Info
Hostname and FQDN Settings
General Information
Debian and Ubuntu
echo "plato" > /etc/hostname
hostname -F /etc/hostname
#SET_HOSTNAME='yes'
CentOS/Fedora
echo "HOSTNAME=plato" >> /etc/sysconfig/network
hostname "plato"
Slackware
echo "plato" > /etc/HOSTNAME
hostname -F /etc/HOSTNAME
Gentoo
echo "HOSTNAME=\"plato\"" > /etc/conf.d/hostname
/etc/init.d/hostname restart
Arch
echo "HOSTNAME=\"plato\"" > /etc/conf.d/hostname
hostname plato
Update /etc/hosts
127.0.0.1 localhost.localdomain localhost
12.34.56.78 plato.example.com plato
DNS Resolver Settings
domain members.linode.com
search members.linode.com
nameserver 98.76.54.32
nameserver 76.54.32.10
options rotate
Static IP Configuration
Debian & Ubuntu
# 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
# This is a second public IP address.
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
/etc/init.d/networking restart
ping 12.34.56.1
ping 98.76.54.1
apt-get remove isc-dhcp-client dhcp3-client dhcpcd
CentOS & Fedora
# 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
# 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
# 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
service network restart
ping 12.34.56.1
ping 98.76.54.1
Arch Linux
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)
/etc/rc.d/network restart
ping 12.34.56.1
ping 98.76.54.1
Gentoo
#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" )
config_eth0=(
"12.34.56.XXX/24"
"192.168.133.XXX/17"
)
routes_eth0=( "default via 12.34.56.1" )
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"
/etc/init.d/net.eth1 stop
rc-update del net.eth1 default
rm /etc/init.d/net.eth1
/etc/init.d/net.eth0 restart
ping 12.34.56.1
ping 98.76.54.1
OpenSuse
# 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
# This is a second public IP address.
IPADDR1='34.56.78.90'
NETMASK1='255.255.255.0'
LABEL1='0'
# eth0:1 - Private IP
# Private IP addresses do not have a gateway.
IPADDR2='192.168.133.234'
NETMASK2='255.255.128.0'
LABEL2='1'
# 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
/etc/init.d/network restart
ping 12.34.56.1
ping 98.76.54.1
相关
Lynx 简明使用指南
源代码安装IPsec-Tools-0.7.2
nginx + php 实现高负载于apache
nginx 应用例子
自己给xen vps添加swap分区。
找出暴力破解centos密码的坏蛋ip。
Linux Static IP Configuration
不改变目前系统架构得情况下,实现高负载
用Suhosin来保护你的php服务器。
nginx 下 No input file specified 显示成 404