Debian and Ubuntu
Debian & Ubuntu
# The loopback interface auto lo iface lo inet loopback # Configuration for eth0 # We no longer need to use aliases (eg. eth0:0 eth0:1 eth0:2) # This line ensures that the interface will be brought up during boot auto eth0 allow-hotplug eth0 # The address and gateway are necessary. # The netmask is taken automatically from the block. # Example: /24 is considered to be a public IP address: netmask 255.255.255.0 iface eth0 inet static address 198.51.100.5/24 gateway 198.51.100.1 # This is a second public IP address iface eth0 inet static address 192.0.2.6/24 # This is a private IP address. Private IPs do not have a gateway (they are not publicly routable). # All you need to specify is the address and the block. The netmask is taken from the block. # Example: /17 is considered to be a private IP address: netmask 255.255.128.0 iface eth0 inet static address 192.168.133.234/17
ifdown -a && ifup -a
CentOS 7 & Fedora 20
# Configuration for eth0 DEVICE=eth0 BOOTPROTO=none ONBOOT=yes # Adding a public IP address. # The netmask is taken from the PREFIX (where 24 is Public IP, 17 is Private IP) IPADDR0=198.51.100.5 PREFIX0=24 # Specifying the gateway GATEWAY0=198.51.100.1 # Adding a second public IP address. IPADDR1=192.0.2.6 PREFIX1=24 # Adding a private IP address. IPADDR2=192.168.133.234 PREFIX2=17
----------------------------------------------------------------------------- 启动刚才配置的网络 nmcli con up "System eth0"
sudo service network restart
# 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=198.51.100.5 NETMASK=255.255.255.0 GATEWAY=198.51.100.1
重启网络 service network restart
# 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='198.51.100.5' NETMASK='255.255.255.0' # eth0:0 # This is a second public IP address. IPADDR1='192.0.2.6' 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'
重启网络 systemctl reload network