网卡配置文件ifcfg-*
在/etc/sysconfig/network-scripts/目录下有不少文件,绝大部分都是脚本类的文件,但有一类ifcfg开头的文件为网卡配置文件(interface config),所有ifcfg开头的文件在启动网络服务的时候都会被加载读取,但具体的文件名ifcfg-XX的XX可以随意命名。
以下是一个(CentOS 7上)ifcfg-XX文件的内容示例。
[root@xuexi ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="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.conf
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
NAME="System eth0"
DNS1=114.114.114.114
DNS2=8.8.8.8
DNS3=114.114.115.115
DNS配置文件/etc/resolv.conf
该文件用于设置DNS指向,以及解析顺序。该文件格式如下:
domain domain_name # 声明本地域名,即解析时自动隐式补齐的域名
search domain_name_list # 指定域名搜索顺序(最多6个),和domain不能共存,若共存了,则后面的行生效
nameserver IP1 # 设置DNS指向,最多3个
nameserver IP2
nameserver 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 www
Trying
"www.malong.com"
;; connection timed out; trying next origin
Trying
"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.host
Trying
"www.host"
;; connection timed out; trying next origin
Trying
"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 origin
Trying
"www.host"
# 默认解析两次
;; connection timed out; no servers could be reached
search关键字的作用和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.host
Trying
"www.host"
;; connection timed out; trying next origin
Trying
"www.host.malongshuai.com"
;; connection timed out; trying next origin
Trying
"www.host.longshuai.com"
;; connection timed out; trying next origin
Trying
"www.host.mashuai.com"
;; connection timed out; no servers could be reached
/etc/services
该文件中记录的是端口和服务的对应关系。
[root@xuexi ~]# grep '^ftp|^ssh'
/etc/services
ftp-data 20/tcp
ftp-data 20/udp
ftp 21/tcp
ftp 21/udp fsp fspd
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
ftp-data 20/sctp # FTP
ftp 21/sctp # FTP
ssh 22/sctp # SSH
ftp-agent 574/tcp # FTP Software Agent System
ftp-agent 574/udp # FTP Software Agent System
sshell 614/tcp # SSLshell
sshell 614/udp # SSLshell
ftps-data 989/tcp # ftp protocol, data, over TLS/SSL
ftps-data 989/udp # ftp protocol, data, over TLS/SSL
ftps 990/tcp # ftp protocol, control, over TLS/SSL
ftps 990/udp # ftp protocol, control, over TLS/SSL
ssh-mgmt 17235/tcp # SSH Tectia Manager
ssh-mgmt 17235/udp # SSH Tectia Manager