CentOS 7配置HostName、IP和DNS
一、配置静态IP
修改或添加下列带注释部分,DEVICE名称按需修改
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-
ifcfg-enp0s5 ifcfg-lo
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-enp0s5
TYPE=Ethernet
BOOTPROTO=static #配置静态IP
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s5
UUID=faa8f6dc-5388-4b2c-9eb3-a936ed099408
DEVICE=enp0s5
NM_CONTROLLED=no #该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理
ONBOOT=yes #开机启动
IPADDR=10.211.55.15 #本机地址
NETMASK=255.255.255.0 #子网掩码
GATEWAY=10.211.55.1 #默认网关
二、配置DNS
- 添加下列带注释部分,dns=no #取消DNS同步配置文件
[root@localhost ~]# vim /etc/NetworkManager/NetworkManager.conf
# Configuration file for NetworkManager.
#
# See "man 5 NetworkManager.conf" for details.
#
# The directories /usr/lib/NetworkManager/conf.d/ and /var/run/NetworkManager/conf.d/
# can contain additional configuration snippets installed by packages. These files are
# read before NetworkManager.conf and have thus lowest priority.
# The directory /etc/NetworkManager/conf.d/ can contain additional configuration
# snippets. Those snippets are merged last and overwrite the settings from this main
# file.
#
# The files within one conf.d/ directory are read in asciibetical order.
#
# If /etc/NetworkManager/conf.d/ contains a file with the same name as
# /usr/lib/NetworkManager/conf.d/, the latter file is shadowed and thus ignored.
# Hence, to disable loading a file from /usr/lib/NetworkManager/conf.d/ you can
# put an empty file to /etc with the same name. The same applies with respect
# to the directory /var/run/NetworkManager/conf.d where files in /var/run shadow
# /usr/lib and are themselves shadowed by files under /etc.
#
# If two files define the same key, the one that is read afterwards will overwrite
# the previous one.
[main]
#plugins=ifcfg-rh,ibft
dns=no #取消DNS同步配置文件
[logging]
# When debugging NetworkManager, enabling debug logging is of great help.
#
# Logfiles contain no passwords and little sensitive information. But please
# check before posting the file online. You can also personally hand over the
# logfile to a NM developer to treat it confidential. Meet us on #nm on freenode.
# Please post full logfiles except minimal modifications of private data.
#
# You can also change the log-level at runtime via
# $ nmcli general logging level TRACE domains ALL
# However, usually it's cleaner to enable debug logging
# in the configuration and restart NetworkManager so that
# debug logging is enabled from the start.
#
# You will find the logfiles in syslog, for example via
# $ journalctl -u NetworkManager
#
# Note that debug logging of NetworkManager can be quite verbose. Some messages
# might be rate-limited by the logging daemon (see RateLimitIntervalSec, RateLimitBurst
# in man journald.conf).
#
#level=TRACE
#domains=ALL
- 修改DNS配置文件,添加nameserver配置
[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 223.5.5.5 #阿里云DNS
二、修改HostName
修改主机名
[root@loaclhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 223.5.5.5 #阿里云DNS
[root@loaclhost ~]# vim /etc/hostname
centos7-15.localdomain