Linux modify IP--gateway--DNS

Modifying the IP address and gateway is a very common operation. When doing related experiments, if it is not set well, it will bring a lot of unnecessary troubles.. 

 

1. Modify IP address

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

DEVICE=eth0

BOOTPROTO=none

BROADCAST=192.168.1.255

IPADDR=192.168.1.33

NETMASK=255.255.255.0

NETWORK=192.168.1.0

ONBOOT=yes

USERCTL=no

PEERDNS=no

TYPE=Ethernet

 

If there are 2 NICs, the information about the second one is stored in the ifcfg-eth1 file. 

 

vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.2.34

NETMASK=255.255.255.0

USERCTL=no

PEERDNS=no

TYPE=Ethernet

NETWORK=192.168.2.0

BROADCAST=192.168.2.255

 

 

 

2. Modify the gateway

vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=Aaron

GATEWAY=192.168.1.1

 

 

 

 

 

3. Restart the network configuration: After modifying the IP and gateway, the network service must be restarted to take effect. 

/etc/init.d/network restart

 

 

4. The DNS configuration information of this machine is in: /etc/resolv.conf

[root@localhost etc]#cat resolv.conf

nameserver xxx.xxx.xxx.xxx

//This is the DNS server address you configured or assigned by DHCP, you can also manually modify this address

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326527303&siteId=291194637