Bo's Oracle Station

查看: 988|回复: 0

课程第13次:2020-03-06星期五

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-3-6 19:31:49 | 显示全部楼层 |阅读模式
1. NMCLI
1.1 一张物理网卡,两个IP的配置
  1. [root@desktop4 network-scripts]# nmcli  con
  2. NAME          UUID                                  TYPE      DEVICE
  3. System ens33  c96bc909-188e-ec64-3a96-6a90982b08ad  ethernet  ens33  
  4. [root@desktop4 network-scripts]# nmcli  con show "System ens33"
  5. connection.id:                          System ens33
  6. connection.uuid:                        c96bc909-188e-ec64-3a96-6a90982b08ad
  7. connection.stable-id:                   --
  8. connection.type:                        802-3-ethernet
  9. connection.interface-name:              ens33
  10. connection.autoconnect:                 yes
  11. connection.autoconnect-priority:        0
  12. connection.autoconnect-retries:         -1 (default)
  13. connection.multi-connect:               0 (default)
  14. connection.auth-retries:                -1
  15. connection.timestamp:                   1583501101
  16. connection.read-only:                   no
  17. connection.permissions:                 --
  18. connection.zone:                        --
  19. connection.master:                      --
  20. connection.slave-type:                  --
  21. connection.autoconnect-slaves:          -1 (default)
  22. connection.secondaries:                 --
  23. connection.gateway-ping-timeout:        0
  24. connection.metered:                     unknown
  25. connection.lldp:                        default
  26. connection.mdns:                        -1 (default)
  27. connection.llmnr:                       -1 (default)
  28. 802-3-ethernet.port:                    --
  29. 802-3-ethernet.speed:                   0
  30. 802-3-ethernet.duplex:                  --
  31. 802-3-ethernet.auto-negotiate:          no
  32. 802-3-ethernet.mac-address:             --
  33. 802-3-ethernet.cloned-mac-address:      --
  34. 802-3-ethernet.generate-mac-address-mask:--
  35. 802-3-ethernet.mac-address-blacklist:   --
  36. 802-3-ethernet.mtu:                     auto
  37. 802-3-ethernet.s390-subchannels:        --
  38. 802-3-ethernet.s390-nettype:            --
  39. 802-3-ethernet.s390-options:            --
  40. 802-3-ethernet.wake-on-lan:             default
  41. 802-3-ethernet.wake-on-lan-password:    --
  42. ipv4.method:                            manual
  43. ipv4.dns:                               --
  44. ipv4.dns-search:                        --
  45. ipv4.dns-options:                       ""
  46. ipv4.dns-priority:                      0
  47. ipv4.addresses:                         192.168.0.4/24
  48. ipv4.gateway:                           192.168.0.254
  49. ipv4.routes:                            --
  50. ipv4.route-metric:                      -1
  51. ipv4.route-table:                       0 (unspec)
  52. ipv4.ignore-auto-routes:                no
  53. ipv4.ignore-auto-dns:                   no
  54. ipv4.dhcp-client-id:                    --
  55. ipv4.dhcp-timeout:                      0 (default)
  56. ipv4.dhcp-send-hostname:                yes
  57. ipv4.dhcp-hostname:                     --
  58. ipv4.dhcp-fqdn:                         --
  59. ipv4.never-default:                     no
  60. ipv4.may-fail:                          yes
  61. ipv4.dad-timeout:                       -1 (default)
  62. ipv6.method:                            ignore
  63. ipv6.dns:                               --
  64. ipv6.dns-search:                        --
  65. ipv6.dns-options:                       ""
  66. ipv6.dns-priority:                      0
  67. ipv6.addresses:                         --
  68. ipv6.gateway:                           --
  69. ipv6.routes:                            --
  70. ipv6.route-metric:                      -1
  71. ipv6.route-table:                       0 (unspec)
  72. ipv6.ignore-auto-routes:                no
  73. ipv6.ignore-auto-dns:                   no
  74. ipv6.never-default:                     no
  75. ipv6.may-fail:                          yes
  76. ipv6.ip6-privacy:                       -1 (unknown)
  77. ipv6.addr-gen-mode:                     stable-privacy
  78. ipv4.gateway:                           192.168.0.254
  79. ipv4.routes:                            --
  80. ipv4.route-metric:                      -1
  81. ipv4.route-table:                       0 (unspec)
  82. ipv4.ignore-auto-routes:                no
  83. ipv4.ignore-auto-dns:                   no
  84. ipv4.dhcp-client-id:                    --
  85. ipv4.dhcp-timeout:                      0 (default)
  86. ipv4.dhcp-send-hostname:                yes
  87. ipv4.dhcp-hostname:                     --
  88. ipv4.dhcp-fqdn:                         --
  89. ipv4.never-default:                     no
  90. ipv4.may-fail:                          yes
  91. ipv4.dad-timeout:                       -1 (default)
  92. ipv6.method:                            ignore
  93. ipv6.dns:                               --
  94. ipv6.dns-search:                        --
  95. ipv6.dns-options:                       ""
  96. ipv6.dns-priority:                      0
  97. ipv6.addresses:                         --
  98. ipv6.gateway:                           --
  99. ipv6.routes:                            --
  100. ipv6.route-metric:                      -1
  101. ipv6.route-table:                       0 (unspec)
  102. ipv6.ignore-auto-routes:                no
  103. ipv6.ignore-auto-dns:                   no
  104. ipv6.never-default:                     no
  105. ipv6.may-fail:                          yes
  106. ipv6.ip6-privacy:                       -1 (unknown)
  107. ipv6.addr-gen-mode:                     stable-privacy
  108. 802-3-ethernet.wake-on-lan-password:    --
  109. ipv4.method:                            manual
  110. ipv4.dns:                               --
  111. ipv4.dns-search:                        --
  112. ipv4.dns-options:                       ""
  113. ipv4.dns-priority:                      0
  114. ipv4.addresses:                         192.168.0.4/24
  115. ipv4.gateway:                           192.168.0.254
  116. ipv4.routes:                            --
  117. ipv4.route-metric:                      -1
  118. ipv4.route-table:                       0 (unspec)
  119. ipv4.ignore-auto-routes:                no
  120. ipv4.ignore-auto-dns:                   no
  121. ipv4.dhcp-client-id:                    --
  122. ipv4.dhcp-timeout:                      0 (default)
  123. ipv4.dhcp-send-hostname:                yes
  124. ipv4.dhcp-hostname:                     --
  125. ipv4.dhcp-fqdn:                         --
  126. ipv4.never-default:                     no
  127. ipv4.may-fail:                          yes
  128. ipv4.dad-timeout:                       -1 (default)
  129. ipv6.method:                            ignore
  130. ipv6.dns:                               --
  131. ipv6.dns-search:                        --
  132. ipv6.dns-options:                       ""
  133. ipv6.dns-priority:                      0
  134. ipv6.addresses:                         --
  135. ipv6.gateway:                           --
  136. [root@desktop4 network-scripts]# nmcli con mod "System ens33" ipv4.addresses '192.168.0.4/24,192.168.0.54/24'
  137. [root@desktop4 network-scripts]# ip addr show
  138. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  139.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  140.     inet 127.0.0.1/8 scope host lo
  141.        valid_lft forever preferred_lft forever
  142.     inet6 ::1/128 scope host
  143.        valid_lft forever preferred_lft forever
  144. 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  145.     link/ether 00:50:56:26:9c:4c brd ff:ff:ff:ff:ff:ff
  146.     inet 192.168.0.4/24 brd 192.168.0.255 scope global noprefixroute ens33
  147.        valid_lft forever preferred_lft forever
  148.     inet6 fe80::250:56ff:fe26:9c4c/64 scope link
  149.        valid_lft forever preferred_lft forever
  150. 3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
  151.     link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
  152. 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
  153.     link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
  154. [root@desktop4 network-scripts]# nmcli con up  "System ens33"
  155. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
  156. [root@desktop4 network-scripts]# ip addr show
  157. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  158.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  159.     inet 127.0.0.1/8 scope host lo
  160.        valid_lft forever preferred_lft forever
  161.     inet6 ::1/128 scope host
  162.        valid_lft forever preferred_lft forever
  163. 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  164.     link/ether 00:50:56:26:9c:4c brd ff:ff:ff:ff:ff:ff
  165.     inet 192.168.0.4/24 brd 192.168.0.255 scope global noprefixroute ens33
  166.        valid_lft forever preferred_lft forever
  167.     inet 192.168.0.54/24 brd 192.168.0.255 scope global secondary noprefixroute ens33
  168.        valid_lft forever preferred_lft forever
  169.     inet6 fe80::250:56ff:fe26:9c4c/64 scope link
  170.        valid_lft forever preferred_lft forever
  171. 3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
  172.     link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
  173. 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
  174.     link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
  175. [root@desktop4 network-scripts]#
复制代码
反映出来的配置文件:
  1. DEVICE=ens33
  2. IPADDR=192.168.0.4
  3. NETMASK=255.255.255.0
  4. GATEWAY=192.168.0.254
  5. TYPE=Ethernet
  6. PROXY_METHOD=none
  7. BROWSER_ONLY=no
  8. BOOTPROTO=none
  9. PREFIX=24
  10. IPADDR1=192.168.0.54
  11. PREFIX1=24
  12. NETMASK1=255.255.255.0
  13. DEFROUTE=yes
  14. IPV4_FAILURE_FATAL=no
  15. IPV6INIT=no
  16. NAME="System ens33"
  17. UUID=c96bc909-188e-ec64-3a96-6a90982b08ad
  18. ONBOOT=yes
复制代码




1.2 手工改方式(别忘了nmcli con reload)
  1. [root@server4 network-scripts]# ls
  2. ifcfg-ens33  ifcfg-ens33:0
  3. [root@server4 network-scripts]# cat ifcfg-ens33:0
  4. DEVICE=ens33:0
  5. IPADDR=192.168.0.204
  6. PREFIX=24
  7. [root@server4 network-scripts]# nmcli con reload
  8. [root@server4 network-scripts]# nmcli con show
  9. NAME   UUID                                  TYPE      DEVICE
  10. ens33  b17ae5d1-d56d-41b6-9fc8-6502bdae4650  ethernet  ens33  
  11. [root@server4 network-scripts]# nmcli dev status
  12. DEVICE      TYPE      STATE      CONNECTION
  13. ens33       ethernet  connected  ens33      
  14. virbr0      bridge    unmanaged  --         
  15. lo          loopback  unmanaged  --         
  16. virbr0-nic  tun       unmanaged  --         
  17. [root@server4 network-scripts]# nmcli con show ens33
  18. connection.id:                          ens33
  19. connection.uuid:                        b17ae5d1-d56d-41b6-9fc8-6502bdae4650
  20. connection.stable-id:                   --
  21. connection.type:                        802-3-ethernet
  22. connection.interface-name:              ens33
  23. connection.autoconnect:                 yes
  24. connection.autoconnect-priority:        0
  25. connection.autoconnect-retries:         -1 (default)
  26. connection.multi-connect:               0 (default)
  27. connection.auth-retries:                -1
  28. connection.timestamp:                   1583501694
  29. connection.read-only:                   no
  30. connection.permissions:                 --
  31. connection.zone:                        --
  32. connection.master:                      --
  33. connection.slave-type:                  --
  34. connection.autoconnect-slaves:          -1 (default)
  35. connection.secondaries:                 --
  36. connection.gateway-ping-timeout:        0
  37. connection.metered:                     unknown
  38. connection.lldp:                        default
  39. connection.mdns:                        -1 (default)
  40. connection.llmnr:                       -1 (default)
  41. 802-3-ethernet.port:                    --
  42. 802-3-ethernet.speed:                   0
  43. 802-3-ethernet.duplex:                  --
  44. 802-3-ethernet.auto-negotiate:          no
  45. 802-3-ethernet.mac-address:             --
  46. 802-3-ethernet.cloned-mac-address:      --
  47. 802-3-ethernet.generate-mac-address-mask:--
  48. 802-3-ethernet.mac-address-blacklist:   --
  49. 802-3-ethernet.mtu:                     auto
  50. 802-3-ethernet.s390-subchannels:        --
  51. 802-3-ethernet.s390-nettype:            --
  52. 802-3-ethernet.s390-options:            --
  53. 802-3-ethernet.wake-on-lan:             default
  54. 802-3-ethernet.wake-on-lan-password:    --
  55. ipv4.method:                            manual
  56. ipv4.dns:                               192.168.0.254
  57. ipv4.dns-search:                        --
  58. ipv4.dns-options:                       ""
  59. ipv4.dns-priority:                      0
  60. ipv4.addresses:                         192.168.0.104/24, 192.168.0.204/24
  61. ipv4.gateway:                           192.168.0.1
  62. ipv4.routes:                            --
  63. ipv4.route-metric:                      -1
  64. ipv4.route-table:                       0 (unspec)
  65. [root@server4 network-scripts]# nmcli con up ens33
  66. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
  67. [root@server4 network-scripts]#
复制代码
1.3 主机名:
/etc/hostname
老的系统是:
  1. [root@instructor sysconfig]# pwd
  2. /etc/sysconfig
  3. [root@instructor sysconfig]# cat network
  4. NETWORKING=yes
  5. HOSTNAME=instructor.example.com
  6. NISDOMAIN=notexample
复制代码

1.4 任何方式改完本机的IP, 都要接着改/etc/hostname和/etc/hosts
/etc/hosts 一定要是两行(三行IPV6)3列:
  1. 127.0.0.1         localhost localhost.localdomain
  2. ::1               localhost6 localhost6.localdomain6
  3. 192.168.0.254     instructor.example.com  instructor

复制代码

2. 网关
2.1临时修改

  1. [root@desktop4 etc]# netstat -nr
  2. Kernel IP routing table
  3. Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
  4. 0.0.0.0         192.168.0.254   0.0.0.0         UG        0 0          0 ens33
  5. 192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 ens33
  6. 192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 ens33
  7. [root@desktop4 etc]# route del -net  0.0.0.0
  8. [root@desktop4 etc]# route add -net  0.0.0.0 gw 192.168.0.1
  9. [root@desktop4 etc]# ping  202.101.98.55
  10. PING 202.101.98.55 (202.101.98.55) 56(84) bytes of data.
  11. 64 bytes from 202.101.98.55: icmp_seq=1 ttl=58 time=12.7 ms
  12. 64 bytes from 202.101.98.55: icmp_seq=2 ttl=58 time=9.08 ms
  13. 64 bytes from 202.101.98.55: icmp_seq=3 ttl=58 time=6.05 ms
  14. ^C
  15. --- 202.101.98.55 ping statistics ---
  16. 3 packets transmitted, 3 received, 0% packet loss, time 5ms
  17. rtt min/avg/max/mdev = 6.048/9.277/12.702/2.721 ms
  18. [root@desktop4 etc]# mtr
复制代码

ping :
  1. #!/bin/sh
  2. sub_1() {
  3. ping -q -n -c 10 -W 1 -i 0.01 -w 1 192.168.0.$1 >/dev/null  2>&1
  4. if [ $? -eq 0 ]
  5. then
  6.   v_nmap=$(nmap -P0  -p 22  192.168.0.$1 | grep open | tr -d '[:blank:]')
  7.   if [ ! -z $v_nmap ]
  8.   then
  9.    echo 192.168.0.$1 >> 11/conclusion.online
  10.   fi
  11. fi
  12. }


  13. rm -f  11/conclusion.online
  14. for i in `seq 1 254`
  15. do
  16. sub_1 $i &
  17. done
  18. wait

  19. echo "OK:"
  20. sed 's/$/$/g' 11/conclusion.online > 11/conclusion.online2
  21. grep -f 11/conclusion.online2 11/conclusion.list


  22. sed 's/$/$/g' 11/conclusion.list > 11/conclusion.list2
  23. echo "STANGE: "
  24. grep -v -f  11/conclusion.list2 11/conclusion.online

  25. echo "NOTONLINE:"
  26. grep -v -f 11/conclusion.online2 11/conclusion.list

复制代码

HOMEWORK RH124 P261-P261
                   RH124 P267-P273












回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-20 20:34 , Processed in 0.035273 second(s), 24 queries .

快速回复 返回顶部 返回列表