linux系统网络配置

一 IP 地址
internet protocol address 网络进程地址就是ip地址。类比家庭地址是为了表明家所在的位置,而ip就是相当于使用该地址的主机的地址,顺着这个ip就能找到这个主机。
ipv 4 :internet protocol version 4 网络进程协议的第四个版本。
ip是由32个二进制位组成,一般八个二进制位 一组,分成四组:
例如:11111111.11111111.11111111.11111110
也可以将其每组的八位二进制数转化成十进制数:255.255.255.254 这两是相等的。
该32位二进制被分为网络位和主机位,而哪些位是网络位,哪些位是主机位是由该ip的子网掩码决定的。
二 子网掩码
作用;用来划分网络区域。
与二进制IP地址相同,子网掩码的长度也是32位,由1和0组成,且1和0分别连续。1在左边,0在右边。单独的子网掩码没有意义,必须配合ip地址使用。子网掩码中1位对应的ip中的数字表示网络位,表示网络区域。0位对应的ip中的数字表示主机位,表示网络区域中的某台主机。例如:

ip:        11111111.11111111.11111111.11111110=255.255.255.254
子网掩码:   11111111.11111111.11111111.00000000=255.255.255.0

该子网掩码中存在24个1所对应的ip地址中的前24位为网络区域,后八位为主机位,所有ip地址255.255.255.254中的前255.255.255表示网络区域,后面的.254表示网络区域中的主机。也可以使用子网掩码中1的个数来表示该子网掩码。
三 ip通信判定
网络位一致,主即位不一致的2个ip可以直接通讯。检测网络是否畅通可以是用 ping 该工具进行检测。例如:

  ip1:  172.25.47.4/24            
  ip2:  172.25.47.104/24
  ip3:  172.25.5.204/1     # ip1与ip2在同一网络区域, 可以直接直接通讯,与ip3不在同一网络区域,无法直接通讯   

在这里插入图片描述
在这里插入图片描述四 查看主机网络ip
1 ip addr show #可以查看单个网卡网络信息,后面加上该网卡名称。

2 ifconfig # 查看该主机上所有的网络设置信息。

五 设定主机ip网络
1 临时设定:

ifconfig   网卡设备名称  ip/子网掩码      #该方式为临时设定,系统重启或者重启网卡服务(NetworkManager)后消失变成修改之前的ip。

2 文本图形模式设置网络。

nmtui  #使用该命令进入文本图形设置网络界面,对网络进行配置。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述3 管理系统网络配置文件的方式设置网络。
命名规则
/etc/sysconfig/network-scripts/ifcfg-xxx #该类文件均为系统网络设置,都会被系统识别,出现内容异常的此类文件会导致系统网络异常。删除网络会导致对应的配置文件被删除
在这里插入图片描述
在这里插入图片描述
直接在此文件中编辑网络配置信息,保存后重启网络服务即可添加新的网络并生效。
并且该文件的名称与该网络的名称并无关系。
静态网络配置文件内容
图
在一个网卡设备中可以设置多个ip
在这里插入图片描述
图
动态网络配置文件内容
图1
4 使用命令的方式进行网络配置。
nmcli # NetworkManager 服务必须开启

nmcli  device  show               #显示网卡设备详细信息 
nmcli device  status              #显示网卡设备连接状态
nmcli  device disconnect   设备名称         # 断开该设备网络
nmcli  device  connect    设备名称         # 连接该设备网络

例如:

[root@client Desktop]# nmcli device show          #查看网卡设备详细信息
GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         52:54:00:7B:E7:D0
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     Ethernet connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/7
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         ip = 172.25.47.104/24, gw = 0.0.0.0
IP6.ADDRESS[1]:                         ip = fe80::5054:ff:fe7b:e7d0/64, gw = ::

GENERAL.DEVICE:                         lo
GENERAL.TYPE:                           loopback
GENERAL.HWADDR:                         00:00:00:00:00:00
GENERAL.MTU:                            65536
GENERAL.STATE:                          10 (unmanaged)
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --
IP4.ADDRESS[1]:                         ip = 127.0.0.1/8, gw = 0.0.0.0
IP6.ADDRESS[1]:                         ip = ::1/128, gw = ::
[root@client Desktop]# nmcli device status    # 显示设备连接状态
DEVICE  TYPE      STATE      CONNECTION            
eth0    ethernet  connected  Ethernet connection 1 
lo      loopback  unmanaged  --                    
[root@client Desktop]# nmcli device disconnect eth0   #断开eth0 设备的连接
[root@client Desktop]# nmcli device status    # 显示设备连接状态  eth0已断开
DEVICE  TYPE      STATE         CONNECTION 
eth0    ethernet  disconnected  --         
lo      loopback  unmanaged     --         
[root@client Desktop]# ifconfig     #查看主机ip
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:7b:e7:d0  txqueuelen 1000  (Ethernet)       #eth0 网卡被断开 未显示ip
        RX packets 23  bytes 1278 (1.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 376  bytes 35566 (34.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@client Desktop]# nmcli device connect eth0    #连接eth0 设备
Device 'eth0' successfully activated with '508993e4-34e9-496c-9566-02b546e84943'.    #成功连接
[root@client Desktop]# nmcli device status     # 显示设备连接状态    
DEVICE  TYPE      STATE      CONNECTION            
eth0    ethernet  connected  Ethernet connection 1 
lo      loopback  unmanaged  --                    
[root@client Desktop]# ifconfig   #查看主机ip
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.47.104  netmask 255.255.255.0  broadcast 172.25.47.255        #eth0 网卡重新连接 显示ip
        inet6 fe80::5054:ff:fe7b:e7d0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:7b:e7:d0  txqueuelen 1000  (Ethernet)
        RX packets 23  bytes 1278 (1.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 403  bytes 39523 (38.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0```

      nmcli connection add                     #添加网络连接     
        nmcli connection  delede              # 删除网络连接
        nmcli  connection  show               # 显示网络连接详细信息
        nmcli   connection  down            # 断开网络连接
        nmcli   connection   up              # 连接网络
        nmcli   connection  modify         # 修改网络信息(动态网络以及静态网络)

例如:```
[root@client Desktop]# nmcli connection show lele  #显示连接名称为lele的连接详细信息
connection.id:                          lele
connection.uuid:                        508993e4-34e9-496c-9566-02b546e84943
connection.interface-name:              --
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
connection.timestamp:                   1554546624
connection.read-only:                   no
connection.permissions:                 
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.secondaries:                 
connection.gateway-ping-timeout:        0
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  full
802-3-ethernet.auto-negotiate:          yes
802-3-ethernet.mac-address:             52:54:00:7B:E7:D0
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.mac-address-blacklist:   
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:        
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:            
ipv4.method:                            manual
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.addresses:                         { ip = 172.25.47.104/24, gw = 0.0.0.0 }
ipv4.routes:                            
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv6.method:                            auto
ipv6.dns:                               
ipv6.dns-search:                        
ipv6.addresses:                         
ipv6.routes:                            
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.dhcp-hostname:                     --
GENERAL.NAME:                           lele
GENERAL.UUID:                           508993e4-34e9-496c-9566-02b546e84943
GENERAL.DEVICES:                        eth0
GENERAL.STATE:                          activated
GENERAL.DEFAULT:                        no
GENERAL.DEFAULT6:                       no
GENERAL.VPN:                            no
GENERAL.ZONE:                           --
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/8
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/4
GENERAL.SPEC-OBJECT:                    --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         ip = 172.25.47.104/24, gw = 0.0.0.0
IP6.ADDRESS[1]:                         ip = fe80::5054:ff:fe7b:e7d0/64, gw = ::
[root@client Desktop]# nmcli connection down lele   #断开名称为lele的网络连接
[root@client Desktop]# ip addr show eth0    # 查看主机网络ip
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000    # 由于连接已经断开未显示ip
    link/ether 52:54:00:7b:e7:d0 brd ff:ff:ff:ff:ff:ff
[root@client Desktop]# nmcli connection up lele   #重新连接名称为lele的网络连接
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)   #提示连接成功
[root@client Desktop]# ip addr show eth0   # 查看主机网络ip
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:7b:e7:d0 brd ff:ff:ff:ff:ff:ff
    inet 172.25.47.104/24 brd 172.25.47.255 scope global eth0      # 由于已经重新连接 显示ip
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe7b:e7d0/64 scope link 
       valid_lft forever preferred_lft forever
[root@client Desktop]# nmcli connection delete lele #删除名称为lele的网络连接
[root@client Desktop]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:7b:e7:d0 brd ff:ff:ff:ff:ff:ff
[root@client Desktop]# nmcli connection add con-name toto ifname eth0 type ethernet ip4 172.25.47.105/24  #添加静态网络连接toto
Connection 'toto' (68825e97-1e5d-475f-877e-01f93d86b6b1) successfully added.
[root@client Desktop]# ip addr show eth0 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:7b:e7:d0 brd ff:ff:ff:ff:ff:ff
    inet 172.25.47.105/24 brd 172.25.47.255 scope global eth0        #成功添加网络 显示所设置的静态ip
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe7b:e7d0/64 scope link 
       valid_lft forever preferred_lft forever

六 NAT 网络地址转换
功能:使得在不同网段的两台主机进行数据传输。
路由器:进行网络地址转换的主机,路由器至少需要两个网卡。可开启防火墙以及其伪装功能(masquerade yes)以及开启内核的路由功能
网关:路由器上与数据来源主机在同一网段的ip地址。用来接收该数据。
1 设置路由器网络

[root@lyq Desktop]# ifconfig    #查看主机网卡设备ip情况 路由器至少存在两块网卡
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:00:2f:0b  txqueuelen 1000  (Ethernet)    # 第一块网卡
        RX packets 96  bytes 16416 (16.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 22  bytes 3508 (3.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:b9:28:a4  txqueuelen 1000  (Ethernet)    #  第二块网卡
        RX packets 45  bytes 7530 (7.3 KiB)  
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 

[root@lyq Desktop]# nmcli connection add con-name eth1 ifname eth1 type ethernet ip4 1.1.1.14/24         #给主机网卡1设置ip
Connection 'eth1' (e113d7e3-6d95-418d-923f-bb57a1f0336b) successfully added.
[root@lyq Desktop]# nmcli connection add con-name eth0 ifname eth0 type ethernet ip4 172.25.47.104/24      #给主机网卡0设置ip
Connection 'eth0' (d6be296f-895c-4920-b6e9-cdf9925a2244) successfully added.
[root@lyq Desktop]# systemctl restart network  #重启网络服务
[root@lyq Desktop]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.47.104  netmask 255.255.255.0  broadcast 172.25.47.255
        inet6 fe80::5054:ff:fe00:2f0b  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:2f:0b  txqueuelen 1000  (Ethernet)
        RX packets 197  bytes 30878 (30.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 134  bytes 19285 (18.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 1.1.1.14  netmask 255.255.255.0  broadcast 1.1.1.255
        inet6 fe80::5054:ff:feb9:28a4  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:b9:28:a4  txqueuelen 1000  (Ethernet)
        RX packets 174  bytes 26394 (25.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 83  bytes 11338 (11.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2 开启防火墙伪装功能

[root@lyq Desktop]# systemctl start firewalld.service    #开启防火墙服务 
[root@lyq Desktop]# firewall-cmd --list-all    #查看服务信息
public (default, active)
  interfaces: eth0 eth1
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no      #伪装功能未开启
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@lyq Desktop]# firewall-cmd --permanent --add-masquerade  #开启伪装功能
success
[root@lyq Desktop]# systemctl restart firewalld.service #  重启防火墙服务
[root@lyq Desktop]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0 eth1
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade:yes    #伪装功能成功开启
  forward-ports: 
  icmp-blocks: 
  rich rules: 

3 开启系统内核路由功能

[root@lyq Desktop]# sysctl -a |grep ip_forward  #从所有系统参数中筛选ip_forward 参数
net.ipv4.ip_forward = 0                         #该值为0,表示系统内核路由功能为开启
[root@lyq Desktop]# vim /etc/sysctl.conf        #修改系统文件 写入 net.ipv4.ip_forward = 1
[root@lyq Desktop]# cat /etc/sysctl.conf        # 查看该文件内容
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward = 1
[root@lyq Desktop]# sysctl -p   #从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载
net.ipv4.ip_forward = 1         # 系统路由功能成功开启

4 设置客户端网关

[root@client Desktop]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 1.1.1.107  netmask 255.255.255.0  broadcast 1.1.1.255          #客户端主机的ip为1.1.1.107
        inet6 fe80::5054:ff:fe7b:e7d0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:7b:e7:d0  txqueuelen 1000  (Ethernet)
        RX packets 243  bytes 32878 (32.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225  bytes 40532 (39.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@client Desktop]# ls /etc/sysconfig/network-scripts/
ifdown-post      ifup-bnep   ifup-routes
ifcfg-eth0-1  ifdown-ppp       ifup-eth    ifup-sit
ifcfg-lo      ifdown-routes    ifup-ippp   ifup-Team
ifdown        ifdown-sit       ifup-ipv6   ifup-TeamPort
ifdown-bnep   ifdown-Team      ifup-isdn   ifup-tunnel
ifdown-eth    ifdown-TeamPort  ifup-plip   ifup-wireless
ifdown-ippp   ifdown-tunnel    ifup-plusb  init.ipv6-global
ifdown-ipv6   ifup             ifup-post   network-functions
ifdown-isdn   ifup-aliases     ifup-ppp    network-functions-ipv6
[root@client Desktop]# cd  /etc/sysconfig/network-scripts/
[root@client network-scripts]# vim ifcfg-eth0-1    #编辑网络配置文件,设置给该网络设置网关
[root@client network-scripts]# cat ifcfg-eth0-1    #查看文件内容
TYPE=Ethernet
BOOTPROTO=none
IPADDR=1.1.1.107
PREFIX=24
NAME=eth0
DEVICE=eth0
ONBOOT=yes
GATEWAY=1.1.1.14      # 在文件中新写入的网关信息,网关为路由器中与该主机在同一网段的ip地址

[root@client network-scripts]# systemctl restart network  # 重启网络服务
[root@client network-scripts]# route -n     # 查看网关信息
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface    # 设置成功
0.0.0.0         1.1.1.14        0.0.0.0         UG    1024   0        0 eth0
1.1.1.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0

5 两台不在同一网段的主机通过路由器进行通讯

[root@client Desktop]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 1.1.1.107  netmask 255.255.255.0  broadcast 1.1.1.255          #客户端主机的ip为1.1.1.107
        inet6 fe80::5054:ff:fe7b:e7d0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:7b:e7:d0  txqueuelen 1000  (Ethernet)
        RX packets 243  bytes 32878 (32.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225  bytes 40532 (39.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@client network-scripts]# ping 172.25.47.250                     #检验通过路由器与主机172.25.47.250进行通讯
PING 172.25.47.250 (172.25.47.250) 56(84) bytes of data.
64 bytes from 172.25.47.250: icmp_seq=1 ttl=63 time=0.403 ms
64 bytes from 172.25.47.250: icmp_seq=2 ttl=63 time=0.557 ms
64 bytes from 172.25.47.250: icmp_seq=3 ttl=63 time=0.612 ms
64 bytes from 172.25.47.250: icmp_seq=4 ttl=63 time=0.607 ms
64 bytes from 172.25.47.250: icmp_seq=5 ttl=63 time=0.588 ms
64 bytes from 172.25.47.250: icmp_seq=6 ttl=63 time=0.526 ms
64 bytes from 172.25.47.250: icmp_seq=7 ttl=63 time=0.593 ms          #  通讯连接成功
64 bytes from 172.25.47.250: icmp_seq=8 ttl=63 time=0.570 ms
^X64 bytes from 172.25.47.250: icmp_seq=9 ttl=63 time=0.605 ms
64 bytes from 172.25.47.250: icmp_seq=10 ttl=63 time=0.571 ms
^C
--- 172.25.47.250 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9000ms
rtt min/avg/max/mdev = 0.403/0.563/0.612/0.060 ms

七 DNS服务器
地址解析 :将域名转换成ip地址过程,为地址解析。
DNS服务器 :提供所有域名的ip地址解析的主机。
将真机作为路由器,使得虚拟机可以通过真机连接网络。

[root@client Desktop]# ping 183.232.231.174
PING 183.232.231.174 (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174: icmp_seq=1 ttl=55 time=42.0 ms
64 bytes from 183.232.231.174: icmp_seq=2 ttl=55 time=42.3 ms
64 bytes from 183.232.231.174: icmp_seq=3 ttl=55 time=41.0 ms
64 bytes from 183.232.231.174: icmp_seq=4 ttl=55 time=41.1 ms
64 bytes from 183.232.231.174: icmp_seq=5 ttl=55 time=40.8 ms
64 bytes from 183.232.231.174: icmp_seq=6 ttl=55 time=41.6 ms
64 bytes from 183.232.231.174: icmp_seq=7 ttl=55 time=40.8 ms
64 bytes from 183.232.231.174: icmp_seq=8 ttl=55 time=41.1 ms
64 bytes from 183.232.231.174: icmp_seq=9 ttl=55 time=41.9 ms
^C
--- 183.232.231.174 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8009ms
rtt min/avg/max/mdev = 40.853/41.455/42.386/0.581 ms

本的解析文件 /etc/hosts. 提供域名ip地址解析

[root@client Desktop]# ping www.baidu.com #通过域名进行里连接
ping: unknown host www.baidu.com          #无法连接
[root@client Desktop]# vim /etc/hosts
[root@client Desktop]# cat  /etc/hosts     #本地解析文件
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.25.254.254 classroom.example.com
172.25.254.254 content.example.com
172.25.231.208  
183.232.231.174 www.baidu.com             #添加www.baidu.com 的域名解析

[root@client Desktop]# ping www.baidu.com  #使用域名成功连接
PING www.baidu.com (183.232.231.174) 56(84) bytes of data.
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=1 ttl=55 time=91.3 ms
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=2 ttl=55 time=67.3 ms
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=3 ttl=55 time=42.7 ms
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=4 ttl=55 time=41.6 ms
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=5 ttl=55 time=42.3 ms
64 bytes from www.baidu.com (183.232.231.174): icmp_seq=6 ttl=55 time=42.1 ms
^C
--- www.baidu.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 41.683/54.612/91.382/18.821 ms

使用DNS服务器进行域名解析。/etc/resolv.conf 存放dns服务器的地址

[root@client Desktop]# vim /etc/resolv.conf    #编辑文件,添加dns服务器的地址
[root@client Desktop]# cat  /etc/resolv.conf 
# Generated by NetworkManager
domain ilt.example.com
search ilt.example.com example.com localdomain.localdomain
nameserver 114.114.114.114                #新添加的dns服务器地址
[root@client Desktop]# ping baidu.com     #使用域名进行网站通讯
PING baidu.com (220.181.57.216) 56(84) bytes of data.
64 bytes from 220.181.57.216: icmp_seq=1 ttl=50 time=32.0 ms
64 bytes from 220.181.57.216: icmp_seq=2 ttl=50 time=30.7 ms
64 bytes from 220.181.57.216: icmp_seq=3 ttl=50 time=31.5 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3004ms
rtt min/avg/max/mdev = 30.757/31.456/32.077/0.560 ms
[root@client Desktop]# ping taobao.com    #使用域名进行网站通讯
PING taobao.com (140.205.94.189) 56(84) bytes of data.
64 bytes from 140.205.94.189: icmp_seq=1 ttl=38 time=49.1 ms
64 bytes from 140.205.94.189: icmp_seq=2 ttl=38 time=45.9 ms
64 bytes from 140.205.94.189: icmp_seq=3 ttl=38 time=49.5 ms
^C
--- taobao.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 45.916/48.183/49.509/1.630 ms

本地域名解析与dns服务器进行解析的优先级 在文件 /etc/nsswitch 39行规定

[root@client Desktop]# vim /etc/nsswitch.conf    #编辑优先级配置文件
[root@client Desktop]# head -n 39 /etc/nsswitch.conf |tail -n 1     #查看该文件39行内容
hosts:      files dns      #表示本地域名解析优先与使用dns服务器进行域名解析
[root@client Desktop]# cat  /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.25.254.254 classroom.example.com
172.25.254.254 content.example.com
172.25.231.208  
172.25.47.250 www.baidu.com     #本地域名解析文件中规定的百度的ip
[root@client Desktop]# ping www.baidu.com   #使用域名连接www.baidu.com 
PING www.baidu.com (172.25.47.250) 56(84) bytes of data.   # 连接的ip为本地解析文件中规定的ip
64 bytes from www.baidu.com (172.25.47.250): icmp_seq=1 ttl=64 time=0.160 ms
64 bytes from www.baidu.com (172.25.47.250): icmp_seq=2 ttl=64 time=0.236 ms
64 bytes from www.baidu.com (172.25.47.250): icmp_seq=3 ttl=64 time=0.196 ms
64 bytes from www.baidu.com (172.25.47.250): icmp_seq=4 ttl=64 time=0.226 ms
^C
--- www.baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.160/0.204/0.236/0.032 ms
[root@client Desktop]# vim /etc/nsswitch.conf    #将使用dns服务器进行域名解析的优先级调高
[root@client Desktop]# head -n 39 /etc/nsswitch.conf |tail -n 1
hosts:      dns files      # dns服务器在前 
[root@client Desktop]# ping www.baidu.com   
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174: icmp_seq=1 ttl=55 time=42.2 ms
64 bytes from 183.232.231.174: icmp_seq=2 ttl=55 time=41.3 ms
^C64 bytes from 183.232.231.174: icmp_seq=3 ttl=55 time=42.0 ms

--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 20114ms
rtt min/avg/max/mdev = 41.388/41.894/42.270/0.371 ms

八 真机使用网线联网
修改/etc/sysconfig/network-scripts/ifcfg-br0 文件,在原有基础上增加:所有用网线的ip,子网以及网关即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值