The first thing to do after installing Linux is to set an IP address for Internet access. This article describes how
. Set static IP address.
(1). Set the command line (this method is only temporary and will not expire after the system is restarted)
[1]. set IP address and mask
Ifconfig Interface Name (such as eth0) ip address netmask Subnet Mask
[2]. Set the Gateway
Route add default gw default Gateway
[3]. Set the DNS server address
Echo "nameserver DNS server address">/etc/resolv. conf
Instance: assume that the IP address of eth0 is 192.168.1.100 and DNS is 192.168.1.12.
Ifconfig eth0 192.168.1.100 netmask 255.255.255.0
Route add default gw 192.168.1.1
Echo "nameserver = 192.168.1.12">/etc/resolv. conf
(2). Modify the file to configure the network (you need to restart the network interface)
[1]. Modify the IP address. File:/etc/sysconfig/network-scripts/ifcfg-Interface Name
Assume that the network interface name is eth0.
Cat <EOF>/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE = eth0 (note: the network interface name is entered here)
BOOTPROTO = none
ONBOOT = yes (Note: whether to start with the System)
IPADDR = 192.168.1.100 (note: the IP address is entered here)
PREFIX = 24 (Note: The Mask Length is entered here)
GATEWAY = 192.168.1.1 (Note: The GATEWAY is written here)
EOF
[2]. Modify DNS
Echo "nameserver DNS server address">/etc/resolv. conf
[3]. Restart the network interface (assuming eth0)
Ifup eth0 (Note: The interface name is written here)
Author: "huangyandong"