linux网络相关文件说明

2021-05-26 10:04:35 浏览数 (1)

网卡配置文件ifcfg-*

在/etc/sysconfig/network-scripts/目录下有不少文件,绝大部分都是脚本类的文件,但有一类ifcfg开头的文件为网卡配置文件(interface config),所有ifcfg开头的文件在启动网络服务的时候都会被加载读取,但具体的文件名ifcfg-XX的XX可以随意命名。

以下是一个(CentOS 7上)ifcfg-XX文件的内容示例。

  1. [root@xuexi ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  2. DEVICE="eth0" # 显示的名称,必须/sys/class/net/目录下的某个网卡名相同
  3. IPV6INIT="no"
  4. BOOTPROTO="dhcp"
  5. ONBOOT=yes
  6. TYPE="Ethernet"
  7. DEFROUTE="yes"
  8. PEERDNS="yes" # 设置为yes时,此文件设置的DNS将覆盖/etc/resolv.conf,
  9. # 若开启了DHCP,则默认为yes,所以dhcp的dns也会覆盖/etc/resolv.conf
  10. PEERROUTES="yes"
  11. IPV4_FAILURE_FATAL="no"
  12. NAME="System eth0"
  13. DNS1=114.114.114.114
  14. DNS2=8.8.8.8
  15. DNS3=114.114.115.115

DNS配置文件/etc/resolv.conf

该文件用于设置DNS指向,以及解析顺序。该文件格式如下:

  1. domain domain_name # 声明本地域名,即解析时自动隐式补齐的域名
  2. search domain_name_list # 指定域名搜索顺序(最多6个),和domain不能共存,若共存了,则后面的行生效
  3. nameserver IP1 # 设置DNS指向,最多3个
  4. nameserver IP2
  5. nameserver IP3
  6. options timeout:n attempts:n # 指定解析超时时间(默认5秒)和解析次数(默认2次)

例如将/etc/resolv.conf设置为下所示,为了测试,暂且不设置nameserver。 domain malong.com

当解析不带点”.”的主机名时,如”www”,认为不是fqdn,将自动加上”.malong.com”变成解析”www.m

  1. [root@xuexi ~]# host -a www
  2. Trying "www.malong.com"
  3. ;; connection timed out; trying next origin
  4. Trying "www"
  5. ;; connection timed out; no servers could be reached

当解析的名称末尾不带点但中间带了点的,如”www.host",认为是fqdn,将直接解析"www.host",解析完这个后再解析加上"malong.com"的名称,即再解析"www.host.malong.com"。

  1. [root@xuexi ~]# host -a www.host
  2. Trying "www.host"
  3. ;; connection timed out; trying next origin
  4. Trying "www.host.malong.com"
  5. ;; connection timed out; no servers could be reached

当解析末尾带点的名称时,如”www.host."认为是完整的fqdn,将直接解析"www.host",解析完后直接结束解析,不会再补齐本地域名再解析。

  1. [root@xuexi ~]# host -a www.host.
  2. Trying "www.host"
  3. ;; connection timed out; trying next origin
  4. Trying "www.host" # 默认解析两次
  5. ;; connection timed out; no servers could be reached

search关键字的作用和domain是一样的,只不过search同时还暗含域名搜索的顺序。例如设置search为如下内容:

  1. search malongshuai.com longshuai.com mashuai.com

此时若解析”www.host",将依次解析"www.host","www.host.malongshuai.com","www.host.longshuai.com","www.host.mashuai.com"。

  1. root@xuexi ~]# host -a www.host
  2. Trying "www.host"
  3. ;; connection timed out; trying next origin
  4. Trying "www.host.malongshuai.com"
  5. ;; connection timed out; trying next origin
  6. Trying "www.host.longshuai.com"
  7. ;; connection timed out; trying next origin
  8. Trying "www.host.mashuai.com"
  9. ;; connection timed out; no servers could be reached

/etc/services

该文件中记录的是端口和服务的对应关系。

  1. [root@xuexi ~]# grep '^ftp|^ssh' /etc/services
  2. ftp-data 20/tcp
  3. ftp-data 20/udp
  4. ftp 21/tcp
  5. ftp 21/udp fsp fspd
  6. ssh 22/tcp # The Secure Shell (SSH) Protocol
  7. ssh 22/udp # The Secure Shell (SSH) Protocol
  8. ftp-data 20/sctp # FTP
  9. ftp 21/sctp # FTP
  10. ssh 22/sctp # SSH
  11. ftp-agent 574/tcp # FTP Software Agent System
  12. ftp-agent 574/udp # FTP Software Agent System
  13. sshell 614/tcp # SSLshell
  14. sshell 614/udp # SSLshell
  15. ftps-data 989/tcp # ftp protocol, data, over TLS/SSL
  16. ftps-data 989/udp # ftp protocol, data, over TLS/SSL
  17. ftps 990/tcp # ftp protocol, control, over TLS/SSL
  18. ftps 990/udp # ftp protocol, control, over TLS/SSL
  19. ssh-mgmt 17235/tcp # SSH Tectia Manager
  20. ssh-mgmt 17235/udp # SSH Tectia Manager

0 人点赞