Centos 7 network configuration for gateway, dns, IP Address Configuration, centosdns
Centos network configuration instance 1. Configure DNSvim/etc/resolv. confnameserver 192.168.0.1
Nameserver 8.8.8.8
Nameserver 8.8.4.4
2. Configure the gateway route add default gw 192.168.1.1 dev eno *
In this way, the gateway is changed to 192.168.1.1, which is temporary. After you restart the system or network card, it will change back to the original gateway. To modify the file permanently, modify the/etc/sysconfig/network file. The main content of this file is as follows (you can manually add items not included in your file ):
Vim/etc/sysconfig/network
NETWORKING = yes # indicates whether the system uses the network, which is generally set to yes. If it is set to no, the network cannot be used.
HOSTNAME = centos # Set the Host Name of the local machine. The host name set here must correspond to the host name set in/etc/hosts.
GATEWAY = 192.168.1.1 # Set the IP address of the GATEWAY connected to the local machine.
3. Configure the IP address vim/etc/sysconfig/network-scripts/ifcfg-eno *
HWADDR = 00: 0C: 29: 8D: 24: 73
TYPE = Ethernet
BOOTPROTO = static # enable static IP addresses
DEFROUTE = yes
PEERDNS = yes
PEERROUTES = yes
20174_failure_fatal = no
IPV6INIT = yes
IPV6_AUTOCONF = yes
Required 6_defroute = yes
IPV6_PEERDNS = yes
20176_peerroutes = yes
20176_failure_fatal = no
NAME = eno16777736
UUID = ae0965e7-22b9-45aa-8ec9-3f0a20a85d11
ONBOOT = yes # enable network connection automatically
IPADDR0 = 192.168.21.128 # Set the IP address
PREFIXO0 = 24 # Set the subnet mask
GATEWAY0 = 192.168.21.2 # Set the Gateway
DNS1 = 8.8.8.8 # Set the primary DNS
DNS2 = 8.8.4.4 # Set backup DNS
: Wq! # Save and exit
4. Set the host name to www.
Vim/etc/hostname # edit the configuration file
Www # modify localhost. localdomain TO www
Vim/etc/hosts # edit the configuration file
127.0.0.1 localhost www # modify localhost. localdomain TO www
5. Restart the service
Ip link set eth0 upi # enable Nic
Ip link set eth0 down # disable the NIC
Service network restart
6. Additional commands
Ip [Option] operation object {link | addr | route ...}
# Ip link show # display Network Interface Information
# Ip link set eth0 upi # enable Nic
# Ip link set eth0 down # disable the NIC
# Ip link set eth0 promisc on # enable mixed Nic Mode
# Ip link set eth0 promisc offi # disable mixed Nic Mode
# Ip link set eth0 txqueuelen 1200 # set the length of the NIC queue
# Ip link set eth0 mtu 1400 # set the maximum transmission unit of the NIC
# Ip addr show # display Nic IP address information
# Ip addr add 192.168.0.1/24 dev eth0 # Set eth0 Nic ip address 192.168.0.1
# Ip addr del 192.168.0.1/24 dev eth0 # Delete the ip address of the eth0 Nic
# Ip route list # view route information
# Ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # Set the gateway of the 192.168.4.0 network segment to 192.168.0.254, and the data goes through the eth0 Interface
# Ip route add default via 192.168.0.254 dev eth0 # Set the default gateway to 192.168.0.254
# Ip route del 192.168.4.0/24 # Delete the gateway of the 192.168.4.0 network segment
# Ip route del default # delete a default route