CentOS 7配置HostName、IP和DNS

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

  1. 添加下列带注释部分,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
  1. 修改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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值