Linux Static IP Settings
IP configuration:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
Bootproto=static
Hwaddr=00:26:18:0b:38:c0
Onboot=yes
ipaddr=192.168.0.2
netmask=255.255.255.0
gateway=192.168.0.1
IP takes effect:
/sbin/ifdown eth0
/sbin/ifup eth0
Notification Gateway Update information:
/etc/init.d/network restart
To configure DNS:
Vi/etc/resolv.conf
NameServer 202.96.134.133
Resolve reboot Effective:
Chattr +i/etc/resolv.conf
Change to read-only
First, understand the traditional network configuration commands:
1. Configure and view network interface conditions using the Ifconfig command
Example 1: Configure eth0 IP and activate the device at the same time:
# ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up
Example 2: Configure IP for the eth0 alias device eth0:1 and add routes
# ifconfig Eth0:1 192.168.4.2
# route add–host 192.168.4.2 Dev eth0:1
Example 3: Activating (disabling) a device
# ifconfig eth0:1 up (down)
Example 4: View all (specified) network interface configurations
# ifconfig (eth0)
2. Configure the routing table with the route command
Example 1: Adding to host routing
# route add–host 192.168.4.2 Dev eth0:1
# route Add–host 192.168.4.1 GW 192.168.4.250
Example 2: Routes added to the network
# route add–net IP netmask MASK eth0
# route add–net IP netmask MASK GW IP
# route Add–net ip/24 eth1
Example 3: Adding a default gateway
# route add default GW IP
Example 4: Removing routes
# route del–host 192.168.4.1 Dev eth0:1
Example 5: View routing information
# route or Route-n (-n indicates that the name is not resolved, the list speed is faster than route)