Modify Linux native IP, gateway and DNS server

  

CentOS modify IP address First turn off the firewall: service iptables stop# ifconfig eth0 192.168.1.80 This will change the IP address to 192.168.1.80 (if you can't find the network, then You may need to change the gateway and DNS, as mentioned later, but when you restart the system or network card, it will change back to the original address. This modification only applies to temporary IP changes. To make permanent changes, modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file. The main contents of this file are as follows (the items that are not in your file, you can add them manually):


# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 #Describe the device alias corresponding to the NIC BOOTPROTO=static #Set the NIC to get For the ip address mode, the option can be static, dhcp or bootpBROADCAST=192.168.1.255 # corresponding subnet broadcast address HWADDR=00:07:E9:05:E8:B4 #corresponding network card physical address IPADDR=12.168.1.80 # This field is required only when the network card is set to static. NETMASK=255.255.255.0 #Network mask corresponding to the network card NETWORK=192.168.1.0 #Network address corresponding to the network card, that is, the network segment ONBOOT=yes # Whether to set when the system starts This network interface, set to yes, activates this device when the system starts.

CentOS Modify Gateway

# route add default gw 192.168.1.1 dev eth0

This will put the gateway Modified to 192.168.1.1, this modification is only temporary, when you restart the system or network card Or changes back to the original gateway. To make permanent changes, modify the /etc/sysconfig/network file. The main contents of this file are as follows (the items that are not in your file, you can add them manually):


# vi /etc/sysconfig/network

NETWORKING=yes # Indicates whether the system uses the network, generally set to yes. If set to no, the network cannot be used. HOSTNAME=centos #Set the host name of this machine. The host name set here should correspond to the host name set in /etc/hosts. GATEWAY=192.168.1.1 #Set the IP address of the gateway connected to this machine.

The above file is modified to restart the network card will take effect:

# service network restart

CentOS modify DNS

The above are all modified After that, when you ping a domain name, you can't get it, but the IP address corresponding to the ping is the same, then we need to modify the DNS. Modify the DNS by modifying the /etc/resolv.conf file:

# vi /etc/resolv.conf

nameserver 8.8.8.8 #googledomain nameserver 8.8.4.4 #googlenameserver

Linux operation is as simple as that. With all the settings above, the system should be available online

Copyright © Windows knowledge All Rights Reserved