在/etc/sysconfig/network-scripts/目录下有不少文件,绝大部分都是脚本类的文件,但有一类ifcfg开头的文件为网卡配置文件(interface config),所有ifcfg开头的文件在启动网络服务的时候都会被加载读取,但具体的文件名ifcfg-XX的XX可以随意命名。
以下是一个(CentOS 7上)ifcfg-XX文件的内容示例。
[root@xuexi ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE="eth0" # 显示的名称,必须/sys/class/net/目录下的某个网卡名相同IPV6INIT="no" BOOTPROTO="dhcp"ONBOOT=yes TYPE="Ethernet"DEFROUTE="yes"PEERDNS="yes" # 设置为yes时,此文件设置的DNS将覆盖/etc/resolv.conf,# 若开启了DHCP,则默认为yes,所以dhcp的dns也会覆盖/etc/resolv.confPEERROUTES="yes"IPV4_FAILURE_FATAL="no"NAME="System eth0"DNS1=114.114.114.114DNS2=8.8.8.8DNS3=114.114.115.115该文件用于设置DNS指向,以及解析顺序。该文件格式如下:
domain domain_name # 声明本地域名,即解析时自动隐式补齐的域名search domain_name_list # 指定域名搜索顺序(最多6个),和domain不能共存,若共存了,则后面的行生效nameserver IP1 # 设置DNS指向,最多3个nameserver IP2nameserver IP3 options timeout:n attempts:n # 指定解析超时时间(默认5秒)和解析次数(默认2次)例如将/etc/resolv.conf设置为下所示,为了测试,暂且不设置nameserver。 domain malong.com
当解析不带点”.”的主机名时,如”www”,认为不是fqdn,将自动加上”.malong.com”变成解析”www.m
[root@xuexi ~]# host -a wwwTrying "www.malong.com";; connection timed out; trying next originTrying "www";; connection timed out; no servers could be reached当解析的名称末尾不带点但中间带了点的,如”www.host",认为是fqdn,将直接解析"www.host",解析完这个后再解析加上"malong.com"的名称,即再解析"www.host.malong.com"。
[root@xuexi ~]# host -a www.hostTrying "www.host";; connection timed out; trying next originTrying "www.host.malong.com";; connection timed out; no servers could be reached当解析末尾带点的名称时,如”www.host."认为是完整的fqdn,将直接解析"www.host",解析完后直接结束解析,不会再补齐本地域名再解析。
[root@xuexi ~]# host -a www.host.Trying "www.host";; connection timed out; trying next originTrying "www.host" # 默认解析两次;; connection timed out; no servers could be reachedsearch关键字的作用和domain是一样的,只不过search同时还暗含域名搜索的顺序。例如设置search为如下内容:
search malongshuai.com longshuai.com mashuai.com此时若解析”www.host",将依次解析"www.host","www.host.malongshuai.com","www.host.longshuai.com","www.host.mashuai.com"。
root@xuexi ~]# host -a www.hostTrying "www.host";; connection timed out; trying next originTrying "www.host.malongshuai.com";; connection timed out; trying next originTrying "www.host.longshuai.com";; connection timed out; trying next originTrying "www.host.mashuai.com";; connection timed out; no servers could be reached该文件中记录的是端口和服务的对应关系。
[root@xuexi ~]# grep '^ftp\|^ssh' /etc/services ftp-data 20/tcpftp-data 20/udpftp 21/tcpftp 21/udp fsp fspdssh 22/tcp # The Secure Shell (SSH) Protocolssh 22/udp # The Secure Shell (SSH) Protocolftp-data 20/sctp # FTPftp 21/sctp # FTPssh 22/sctp # SSHftp-agent 574/tcp # FTP Software Agent Systemftp-agent 574/udp # FTP Software Agent Systemsshell 614/tcp # SSLshellsshell 614/udp # SSLshellftps-data 989/tcp # ftp protocol, data, over TLS/SSLftps-data 989/udp # ftp protocol, data, over TLS/SSLftps 990/tcp # ftp protocol, control, over TLS/SSLftps 990/udp # ftp protocol, control, over TLS/SSLssh-mgmt 17235/tcp # SSH Tectia Managerssh-mgmt 17235/udp # SSH Tectia Manager原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。