Linux system operation and maintenance notes (3), setting IP and DNS
Manually configure a static IP address
That is, manually configure the IP address, subnet mask, gateway and DNS.
vi /etc/sysconfig/network-scripts/ifcfg-eth0 Edit the configuration file of the local network card
Mainly check whether the following items are consistent with those given below.
ONBOOT=yes BOOTPROTO=none IPADDR=192.168.1.66 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=192.168.1.1
The second item means that the dhcp service is not used. If a static ip address is manually configured, the value of BOOTPROTO can be none or static.
The third item is to set the IP address.
The fourth item means to set the subnet mask.
The fifth item means setting the gateway.
The sixth item means setting the preferred DNS server. In fact, DNS has its own configuration file /etc/resolv.conf. To set DNS here is to write it into the DNS configuration file /etc/resolv.conf.
Then, execute the following command to restart the network service.
service network restart
Temporarily set IP address
If you do not need to set the IP address permanently, you can also use the following command to temporarily set the IP address, which will be invalid after the system restarts.
ifconfig eth0 192.168.1.3 Temporarily configure the IP address of the local network card eth0, and the Linux restart will fail.