note_12.3.3_网络配置练习

ifconfig

[root@localhost ~]# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.223.129  netmask 255.255.255.0  broadcast 192.168.223.255
        inet6 fe80::e537:3c3b:9ce6:ce37  prefixlen 64  scopeid 0x20
        ether 00:0c:29:ae:46:bc  txqueuelen 1000  (Ethernet)
        RX packets 3787  bytes 260761 (254.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 873  bytes 149916 (146.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 68  bytes 5920 (5.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 68  bytes 5920 (5.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ifconfig 配置接口ip

[root@localhost ~]# ifconfig lo
lo: flags=73  mtu 65536
        inet 192.168.1.1  netmask 255.255.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6272 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6272 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifconfig lo 127.0.0.1/8 promisc up
[root@localhost ~]# ifconfig lo
lo: flags=329  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6272 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6272 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifconfig lo -promisc
[root@localhost ~]# ifconfig lo
lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6272 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6272 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

route

查看路由表

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 ens33
192.168.223.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.223.2   0.0.0.0         UG    100    0        0 ens33
192.168.223.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

添加路由

[root@localhost ~]# route add -net 172.16.0.0/16  dev lo
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 ens33
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 lo
192.168.223.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

删除路由

[root@localhost ~]# route del -net 172.16.0.0/16
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 ens33
192.168.223.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

netstat

-r显示路由

[root@localhost ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.223.2   0.0.0.0         UG        0 0          0 ens33
192.168.223.0   0.0.0.0         255.255.255.0   U         0 0          0 ens33
[root@localhost ~]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         gateway         0.0.0.0         UG        0 0          0 ens33
192.168.223.0   0.0.0.0         255.255.255.0   U         0 0          0 ens33

-t -u 查看tcp udp链接

[root@localhost ~]# netstat -tua
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN     
tcp        0      0 localhost.localdoma:ssh 192.168.223.1:sstsys-lm ESTABLISHED
tcp        0     52 localhost.localdoma:ssh 192.168.223.1:14472     ESTABLISHED
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN     
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                          
udp        0      0 localhost:323           0.0.0.0:*                          
udp6       0      0 localhost:323           [::]:*                             
[root@localhost ~]# netstat -tuan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.223.129:22      192.168.223.1:1692      ESTABLISHED
tcp        0     52 192.168.223.129:22      192.168.223.1:14472     ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp6       0      0 ::1:323                 :::*                               

-l -p

[root@localhost ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6428/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      6571/master         
tcp6       0      0 :::22                   :::*                    LISTEN      6428/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      6571/master        

查看接口统计数据

[root@localhost ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33            1500     7974      0      0 0          2696      0      0      0 BMRU
lo              65536       72      0      0 0            72      0      0      0 LRU
[root@localhost ~]# netstat -Iens33
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33            1500     7994      0      0 0          2708      0      0      0 BMRU

ifdown ifup

[root@localhost ~]# ifdown lo
[root@localhost ~]# ifconfig lo
lo: flags=8  mtu 65536
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6272 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6272 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifup lo
[root@localhost ~]# ifconfig lo
lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6272 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6272 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

hostname

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 5f47125a1faf4b438a9b7aec3758819e
           Boot ID: a7b873fd1eb64e56a8f1bd3d06e31964
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-957.el7.x86_64
      Architecture: x86-64

[root@localhost ~]# uname
Linux
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

/etc/sysconfig/network
HOSTNAME=

DNS配置

/etc/resolv.conf

[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.223.2

ip link

show / list

[root@localhost ~]# ip link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:ae:46:bc brd ff:ff:ff:ff:ff:ff

set [down/up name multicast on/off...]

[root@localhost ~]# ip link set lo down
[root@localhost ~]# ip link list lo
1: lo:  mtu 65536 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[root@localhost ~]# ip link set lo up && ip link list lo
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

ip address

add

[root@localhost ~]# ip addr add 172.16.0.1/16 dev lo
[root@localhost ~]# ip addr show lo
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 172.16.0.1/16 scope global lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

delete

[root@localhost ~]# ip addr delete 172.16.0.1/16 dev lo && ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

flush

[root@localhost ~]# ip addr flush lo && ip addr show lo
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

ip route

note_12.3.3_网络配置练习_第1张图片
ip route add

note_12.3.3_网络配置练习_第2张图片
ip route delete

ss命令

[root@localhost ~]# ss -tm
State      Recv-Q Send-Q                     Local Address:Port                                      Peer Address:Port                
ESTAB      0      52                       192.168.223.129:ssh                                      192.168.223.1:4244                 
     skmem:(r0,rb369280,t0,tb87040,f1792,w2304,o0,bl0,d0)
[root@localhost ~]# ss -to
State      Recv-Q Send-Q                     Local Address:Port                                      Peer Address:Port                
ESTAB      0      52                       192.168.223.129:ssh                                      192.168.223.1:4244                  timer:(on,238ms,0)

配置文件

接口配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE
路由配置文件:/etc/sysconfig/network-scripts/route-IFACE

nmcli

[root@localhost ~]# nmcli device show lo
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]:                         127.0.0.1/8
IP4.GATEWAY:                            --
IP6.GATEWAY:                            --

你可能感兴趣的:(note_12.3.3_网络配置练习)