Centos IP and DNS Settings
- 2020-05-17 07:08:02
- OfStack
This paper describes the Settings of IP and DNS under Centos in detail. I will share it with you for your reference as follows:
1. CentOS modifies DNS
Modify the DNS configuration file for the corresponding network card
# vi /etc/resolv.conf
Modify the following
nameserver 8.8.8.8 #google Domain name server
nameserver 8.8.4.4 #google Domain name server
2. Modify the gateway with CentOS
Modify the gateway configuration file for the corresponding network card
[root@centos]# vi /etc/sysconfig/network
Modify the following
NETWORKING=yes(indicates whether the system USES network or not, 1 is generally set to yes. If set to no, you will not be able to use the network, and many system servers will not be able to start.)
HOSTNAME=centos(set the hostname of the machine, which corresponds to the hostname set in /etc/hosts)
GATEWAY=192.168.1.1(sets the IP address of the gateway for the local connection. For example, the gateway is 10.0.0.2)
3. CentOS modifies IP address
Modify the configuration file for the IP address of the corresponding network card
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the following
DEVICE=eth0 # describes the device alias for the network card, such as ifcfg-eth0 in the file eth0
The possible options are static, dhcp or bootp, which correspond to the statically specified ip address, ip address obtained through dhcp protocol, and ip address obtained through bootp protocol
BROADCAST=192.168.0.255 # corresponding subnet broadcast address
HWADDR = 00:07: E9:05: E8: B4 # corresponds to the network card physical address
IPADDR=12.168.1.2 # this field specifies the ip address for the network card if you set it to obtain the ip address statically
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0 # network mask for the network card
NETWORK=192.168.1.0 # network card corresponding to the network address
Whether this network interface is set when system is started or not, when system is set to yes, the device will be activated when system is started
4. Restart the network configuration
# service network restart
or
# /etc/init.d/network restart
Modify the IP address
Effective immediately:
# ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Effective upon startup:
Modify/etc sysconfig/network - scripts/ifcfg - eth0
Modify gateway Default Gateway
Effective immediately:
# route add default gw 192.168.0.1 dev eth0
Effective upon startup:
Modify/etc/sysconfig/network
Modify DNS
Modify/etc/resolv conf
The modification can take effect immediately after it is started
Modify host name
Effective immediately:
# hostname centos1
Effective upon startup:
Modify/etc/sysconfig/network
Manually change centos to static IP
1, first searched 1, and got the following explanation
IP IP address
Netmark subnet mask
Gateway default gateway
HostName host name
DomainName domain name
DNS DNS IP
2. There are often files that need to be modified
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/resolv.conf
/etc/hosts
The 'connect:Network is unreachable error' problem occurs. VirtualBox is connected by Bridged Adapter.
Modify the virtual machine's IP address by modifying /etc/sysconfig/ network-scripts/ifcfg-eth0 to network and netmask.
I found that ping is the same as network and netmask, so I concluded that it should be the routing configuration problem of the virtual machine operating system. I tried to directly modify the system file /etc/sysconfig/ network-scripts/route-eth0 to add 'defult via 192.168.0.1 '(192.168.0.1 is the IP address of my router, which can be modified according to my own situation).
I went to /etc/sysconfig/ network-scripts/and found that there was no route-eth0 at all, so I created one myself and added 'defult via 192.168.0.1 'to the file.
Run '/ etc/init d/network restart' restart network, 1 slice ok! It turned out that the problem really was routing.
I already used the route add command to configure routing, but it failed after a reboot, which was a bit careless
I hope this article has helped you with CentOS server management.