|
1. NMCLI
1.1 一张物理网卡,两个IP的配置
- [root@desktop4 network-scripts]# nmcli con
- NAME UUID TYPE DEVICE
- System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33
- [root@desktop4 network-scripts]# nmcli con show "System ens33"
- connection.id: System ens33
- connection.uuid: c96bc909-188e-ec64-3a96-6a90982b08ad
- connection.stable-id: --
- connection.type: 802-3-ethernet
- connection.interface-name: ens33
- connection.autoconnect: yes
- connection.autoconnect-priority: 0
- connection.autoconnect-retries: -1 (default)
- connection.multi-connect: 0 (default)
- connection.auth-retries: -1
- connection.timestamp: 1583501101
- connection.read-only: no
- connection.permissions: --
- connection.zone: --
- connection.master: --
- connection.slave-type: --
- connection.autoconnect-slaves: -1 (default)
- connection.secondaries: --
- connection.gateway-ping-timeout: 0
- connection.metered: unknown
- connection.lldp: default
- connection.mdns: -1 (default)
- connection.llmnr: -1 (default)
- 802-3-ethernet.port: --
- 802-3-ethernet.speed: 0
- 802-3-ethernet.duplex: --
- 802-3-ethernet.auto-negotiate: no
- 802-3-ethernet.mac-address: --
- 802-3-ethernet.cloned-mac-address: --
- 802-3-ethernet.generate-mac-address-mask:--
- 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: --
- 802-3-ethernet.wake-on-lan: default
- 802-3-ethernet.wake-on-lan-password: --
- ipv4.method: manual
- ipv4.dns: --
- ipv4.dns-search: --
- ipv4.dns-options: ""
- ipv4.dns-priority: 0
- ipv4.addresses: 192.168.0.4/24
- ipv4.gateway: 192.168.0.254
- ipv4.routes: --
- ipv4.route-metric: -1
- ipv4.route-table: 0 (unspec)
- ipv4.ignore-auto-routes: no
- ipv4.ignore-auto-dns: no
- ipv4.dhcp-client-id: --
- ipv4.dhcp-timeout: 0 (default)
- ipv4.dhcp-send-hostname: yes
- ipv4.dhcp-hostname: --
- ipv4.dhcp-fqdn: --
- ipv4.never-default: no
- ipv4.may-fail: yes
- ipv4.dad-timeout: -1 (default)
- ipv6.method: ignore
- ipv6.dns: --
- ipv6.dns-search: --
- ipv6.dns-options: ""
- ipv6.dns-priority: 0
- ipv6.addresses: --
- ipv6.gateway: --
- ipv6.routes: --
- ipv6.route-metric: -1
- ipv6.route-table: 0 (unspec)
- ipv6.ignore-auto-routes: no
- ipv6.ignore-auto-dns: no
- ipv6.never-default: no
- ipv6.may-fail: yes
- ipv6.ip6-privacy: -1 (unknown)
- ipv6.addr-gen-mode: stable-privacy
- ipv4.gateway: 192.168.0.254
- ipv4.routes: --
- ipv4.route-metric: -1
- ipv4.route-table: 0 (unspec)
- ipv4.ignore-auto-routes: no
- ipv4.ignore-auto-dns: no
- ipv4.dhcp-client-id: --
- ipv4.dhcp-timeout: 0 (default)
- ipv4.dhcp-send-hostname: yes
- ipv4.dhcp-hostname: --
- ipv4.dhcp-fqdn: --
- ipv4.never-default: no
- ipv4.may-fail: yes
- ipv4.dad-timeout: -1 (default)
- ipv6.method: ignore
- ipv6.dns: --
- ipv6.dns-search: --
- ipv6.dns-options: ""
- ipv6.dns-priority: 0
- ipv6.addresses: --
- ipv6.gateway: --
- ipv6.routes: --
- ipv6.route-metric: -1
- ipv6.route-table: 0 (unspec)
- ipv6.ignore-auto-routes: no
- ipv6.ignore-auto-dns: no
- ipv6.never-default: no
- ipv6.may-fail: yes
- ipv6.ip6-privacy: -1 (unknown)
- ipv6.addr-gen-mode: stable-privacy
- 802-3-ethernet.wake-on-lan-password: --
- ipv4.method: manual
- ipv4.dns: --
- ipv4.dns-search: --
- ipv4.dns-options: ""
- ipv4.dns-priority: 0
- ipv4.addresses: 192.168.0.4/24
- ipv4.gateway: 192.168.0.254
- ipv4.routes: --
- ipv4.route-metric: -1
- ipv4.route-table: 0 (unspec)
- ipv4.ignore-auto-routes: no
- ipv4.ignore-auto-dns: no
- ipv4.dhcp-client-id: --
- ipv4.dhcp-timeout: 0 (default)
- ipv4.dhcp-send-hostname: yes
- ipv4.dhcp-hostname: --
- ipv4.dhcp-fqdn: --
- ipv4.never-default: no
- ipv4.may-fail: yes
- ipv4.dad-timeout: -1 (default)
- ipv6.method: ignore
- ipv6.dns: --
- ipv6.dns-search: --
- ipv6.dns-options: ""
- ipv6.dns-priority: 0
- ipv6.addresses: --
- ipv6.gateway: --
- [root@desktop4 network-scripts]# nmcli con mod "System ens33" ipv4.addresses '192.168.0.4/24,192.168.0.54/24'
- [root@desktop4 network-scripts]# ip addr show
- 1: lo: <LOOPBACK,UP,LOWER_UP> 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
- 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
- link/ether 00:50:56:26:9c:4c brd ff:ff:ff:ff:ff:ff
- inet 192.168.0.4/24 brd 192.168.0.255 scope global noprefixroute ens33
- valid_lft forever preferred_lft forever
- inet6 fe80::250:56ff:fe26:9c4c/64 scope link
- valid_lft forever preferred_lft forever
- 3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
- link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
- 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
- link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
- [root@desktop4 network-scripts]# nmcli con up "System ens33"
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
- [root@desktop4 network-scripts]# ip addr show
- 1: lo: <LOOPBACK,UP,LOWER_UP> 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
- 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
- link/ether 00:50:56:26:9c:4c brd ff:ff:ff:ff:ff:ff
- inet 192.168.0.4/24 brd 192.168.0.255 scope global noprefixroute ens33
- valid_lft forever preferred_lft forever
- inet 192.168.0.54/24 brd 192.168.0.255 scope global secondary noprefixroute ens33
- valid_lft forever preferred_lft forever
- inet6 fe80::250:56ff:fe26:9c4c/64 scope link
- valid_lft forever preferred_lft forever
- 3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
- link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
- 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
- link/ether 52:54:00:99:cc:19 brd ff:ff:ff:ff:ff:ff
- [root@desktop4 network-scripts]#
复制代码 反映出来的配置文件:
- DEVICE=ens33
- IPADDR=192.168.0.4
- NETMASK=255.255.255.0
- GATEWAY=192.168.0.254
- TYPE=Ethernet
- PROXY_METHOD=none
- BROWSER_ONLY=no
- BOOTPROTO=none
- PREFIX=24
- IPADDR1=192.168.0.54
- PREFIX1=24
- NETMASK1=255.255.255.0
- DEFROUTE=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=no
- NAME="System ens33"
- UUID=c96bc909-188e-ec64-3a96-6a90982b08ad
- ONBOOT=yes
复制代码
1.2 手工改方式(别忘了nmcli con reload)
- [root@server4 network-scripts]# ls
- ifcfg-ens33 ifcfg-ens33:0
- [root@server4 network-scripts]# cat ifcfg-ens33:0
- DEVICE=ens33:0
- IPADDR=192.168.0.204
- PREFIX=24
- [root@server4 network-scripts]# nmcli con reload
- [root@server4 network-scripts]# nmcli con show
- NAME UUID TYPE DEVICE
- ens33 b17ae5d1-d56d-41b6-9fc8-6502bdae4650 ethernet ens33
- [root@server4 network-scripts]# nmcli dev status
- DEVICE TYPE STATE CONNECTION
- ens33 ethernet connected ens33
- virbr0 bridge unmanaged --
- lo loopback unmanaged --
- virbr0-nic tun unmanaged --
- [root@server4 network-scripts]# nmcli con show ens33
- connection.id: ens33
- connection.uuid: b17ae5d1-d56d-41b6-9fc8-6502bdae4650
- connection.stable-id: --
- connection.type: 802-3-ethernet
- connection.interface-name: ens33
- connection.autoconnect: yes
- connection.autoconnect-priority: 0
- connection.autoconnect-retries: -1 (default)
- connection.multi-connect: 0 (default)
- connection.auth-retries: -1
- connection.timestamp: 1583501694
- connection.read-only: no
- connection.permissions: --
- connection.zone: --
- connection.master: --
- connection.slave-type: --
- connection.autoconnect-slaves: -1 (default)
- connection.secondaries: --
- connection.gateway-ping-timeout: 0
- connection.metered: unknown
- connection.lldp: default
- connection.mdns: -1 (default)
- connection.llmnr: -1 (default)
- 802-3-ethernet.port: --
- 802-3-ethernet.speed: 0
- 802-3-ethernet.duplex: --
- 802-3-ethernet.auto-negotiate: no
- 802-3-ethernet.mac-address: --
- 802-3-ethernet.cloned-mac-address: --
- 802-3-ethernet.generate-mac-address-mask:--
- 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: --
- 802-3-ethernet.wake-on-lan: default
- 802-3-ethernet.wake-on-lan-password: --
- ipv4.method: manual
- ipv4.dns: 192.168.0.254
- ipv4.dns-search: --
- ipv4.dns-options: ""
- ipv4.dns-priority: 0
- ipv4.addresses: 192.168.0.104/24, 192.168.0.204/24
- ipv4.gateway: 192.168.0.1
- ipv4.routes: --
- ipv4.route-metric: -1
- ipv4.route-table: 0 (unspec)
- [root@server4 network-scripts]# nmcli con up ens33
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
- [root@server4 network-scripts]#
复制代码 1.3 主机名:
/etc/hostname
老的系统是:
- [root@instructor sysconfig]# pwd
- /etc/sysconfig
- [root@instructor sysconfig]# cat network
- NETWORKING=yes
- HOSTNAME=instructor.example.com
- NISDOMAIN=notexample
复制代码
1.4 任何方式改完本机的IP, 都要接着改/etc/hostname和/etc/hosts
/etc/hosts 一定要是两行(三行IPV6)3列:
- 127.0.0.1 localhost localhost.localdomain
- ::1 localhost6 localhost6.localdomain6
- 192.168.0.254 instructor.example.com instructor
复制代码
2. 网关
2.1临时修改
- [root@desktop4 etc]# netstat -nr
- Kernel IP routing table
- Destination Gateway Genmask Flags MSS Window irtt Iface
- 0.0.0.0 192.168.0.254 0.0.0.0 UG 0 0 0 ens33
- 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
- 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
- [root@desktop4 etc]# route del -net 0.0.0.0
- [root@desktop4 etc]# route add -net 0.0.0.0 gw 192.168.0.1
- [root@desktop4 etc]# ping 202.101.98.55
- PING 202.101.98.55 (202.101.98.55) 56(84) bytes of data.
- 64 bytes from 202.101.98.55: icmp_seq=1 ttl=58 time=12.7 ms
- 64 bytes from 202.101.98.55: icmp_seq=2 ttl=58 time=9.08 ms
- 64 bytes from 202.101.98.55: icmp_seq=3 ttl=58 time=6.05 ms
- ^C
- --- 202.101.98.55 ping statistics ---
- 3 packets transmitted, 3 received, 0% packet loss, time 5ms
- rtt min/avg/max/mdev = 6.048/9.277/12.702/2.721 ms
- [root@desktop4 etc]# mtr
复制代码
ping :
- #!/bin/sh
- sub_1() {
- ping -q -n -c 10 -W 1 -i 0.01 -w 1 192.168.0.$1 >/dev/null 2>&1
- if [ $? -eq 0 ]
- then
- v_nmap=$(nmap -P0 -p 22 192.168.0.$1 | grep open | tr -d '[:blank:]')
- if [ ! -z $v_nmap ]
- then
- echo 192.168.0.$1 >> 11/conclusion.online
- fi
- fi
- }
- rm -f 11/conclusion.online
- for i in `seq 1 254`
- do
- sub_1 $i &
- done
- wait
- echo "OK:"
- sed 's/$/$/g' 11/conclusion.online > 11/conclusion.online2
- grep -f 11/conclusion.online2 11/conclusion.list
- sed 's/$/$/g' 11/conclusion.list > 11/conclusion.list2
- echo "STANGE: "
- grep -v -f 11/conclusion.list2 11/conclusion.online
- echo "NOTONLINE:"
- grep -v -f 11/conclusion.online2 11/conclusion.list
复制代码
HOMEWORK RH124 P261-P261 RH124 P267-P273
|
|