1、总结ip分类以及每个分类可以分配的IP数量
IP地址组成:网络id、主机id
IP地址分类:
A类:1-126.x.y.z
网络ID位最高8位,主机ID是后24位
网络数:126=2^7(可变是的网络ID位数)-2
每个网络中的主机数:2^24-2=16777214
B类:127-191.x.y.z
网络ID位是最高16位,主机ID是16位低位
网络数:2^14=16384
每个网络中的主机数:2^16-2=65534
C类:192-223.x.y.z
网络ID位是最高24位,主机ID是8位低位
网络数:2^21=2097152
每个网络中的主机数:2^8-2=254
D类:组(多)播,1111.X.Y.Z: 224-239.X.Y.Z
2、总结IP配置方法
centos:
[root@centos8 ~]# ll /etc/sysconfig/network-scripts/
total 4
-rw-r--r-- 1 root root 364 Dec 23 20:12 ifcfg-eth0
[root@centos8 ~]# nmcli con modify eth0 ipv4.address 10.0.0.8/24 ipv4.gateway 10.0.0.251 ipv4.dns 233.6.6.6 ipv4.method manual
[root@centos8 ~]# nmcli con reload
[root@centos8 ~]# nmcli con up eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
查看ip和gateway
[root@centos8 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:17 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::64ed:295f:cba6:8479/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@centos8 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.251 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
查看DNS:
[root@centos8 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search yyang
nameserver 223.6.6.6
Ubuntu:
root@ubuntu1804:/etc/netplan# vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [10.0.0.12/24]
gateway4: 10.0.0.251
optional: true
nameservers:
addresses: [223.6.6.6,223.5.5.5]
root@ubuntu1804:/etc/netplan# netplan apply
查看ip和gateway:
root@ubuntu1804:/etc/netplan# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:73:be:9d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.12/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe73:be9d/64 scope link
valid_lft forever preferred_lft forever
root@ubuntu1804:/etc/netplan# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.251 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
查看DNS :
root@ubuntu1804:/etc/netplan# systemd-resolve --status
Global
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
22.172.in-addr.arpa
23.172.in-addr.arpa
24.172.in-addr.arpa
25.172.in-addr.arpa
26.172.in-addr.arpa
27.172.in-addr.arpa
28.172.in-addr.arpa
29.172.in-addr.arpa
30.172.in-addr.arpa
31.172.in-addr.arpa
corp
d.f.ip6.arpa
home
internal
intranet
lan
local
private
Global
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
22.172.in-addr.arpa
23.172.in-addr.arpa
24.172.in-addr.arpa
25.172.in-addr.arpa
26.172.in-addr.arpa
27.172.in-addr.arpa
28.172.in-addr.arpa
29.172.in-addr.arpa
30.172.in-addr.arpa
31.172.in-addr.arpa
corp
d.f.ip6.arpa
home
internal
intranet
lan
local
private
test
Link 2 (eth0)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 223.6.6.6
223.5.5.5
3、使用nmcli实现bonding
[root@centos8 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:17 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::64ed:295f:cba6:8479/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
inet6 fe80::46a:6652:6179:95f1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
9: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:2b brd ff:ff:ff:ff:ff:ff
[root@centos8 ~]# nmcli con
NAME UUID TYPE DEVICE
Wired connection 1 b8af1ac4-ff31-3bf2-9265-5fb84a960233 ethernet eth1
eth0 4ccf8f99-03d0-3b41-8969-b70e7810d6e3 ethernet eth0
Wired connection 2 e5539525-106f-3b41-8d1b-6cf4823a47ad ethernet --
[root@centos8 ~]# nmcli con add type bond con-name bond0 ifname bond0 mode active-backup
Connection 'bond0' (6e7f3537-3de3-4a90-a880-03eb15eccd69) successfully added.
[root@centos8 ~]# nmcli con add type bond-slave ifname eth1 master bond0
Connection 'bond-slave-eth1' (02069f67-e801-419c-9395-03d4f41ec808) successfully added.
[root@centos8 ~]# nmcli con add type bond-slave ifname eth2 master bond0
Connection 'bond-slave-eth2' (befaaaae-174b-4158-945d-ccd5fb52d058) successfully added.
[root@centos8 ~]# nmcli con
NAME UUID TYPE DEVICE
bond0 6e7f3537-3de3-4a90-a880-03eb15eccd69 bond bond0
eth0 4ccf8f99-03d0-3b41-8969-b70e7810d6e3 ethernet eth0
bond-slave-eth1 02069f67-e801-419c-9395-03d4f41ec808 ethernet eth1
bond-slave-eth2 befaaaae-174b-4158-945d-ccd5fb52d058 ethernet eth2
Wired connection 1 b8af1ac4-ff31-3bf2-9265-5fb84a960233 ethernet --
Wired connection 2 e5539525-106f-3b41-8d1b-6cf4823a47ad ethernet --
[root@centos8 ~]# nmcli con up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/47)
[root@centos8 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:17 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::64ed:295f:cba6:8479/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
9: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
12: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
inet6 fe80::44e1:64e7:d0ef:c70c/64 scope link tentative noprefixroute
valid_lft forever preferred_lft forever
[root@centos8 network-scripts]# nmcli con modify bond0 ipv4.address 10.0.0.9/24 ipv4.gateway 10.0.0.251 ipv4.dns 233.6.6.6 ipv4.method manual
[root@centos8 network-scripts]# nmcli con reload
[root@centos8 network-scripts]# nmcli con up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/54)
[root@centos8 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:17 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::64ed:295f:cba6:8479/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
9: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
13: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:7a:4b:21 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.9/24 brd 10.0.0.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
inet6 fe80::44e1:64e7:d0ef:c70c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@centos8 ~]# nmcli con
NAME UUID TYPE DEVICE
eth0 4ccf8f99-03d0-3b41-8969-b70e7810d6e3 ethernet eth0
bond0 6e7f3537-3de3-4a90-a880-03eb15eccd69 bond bond0
bond-slave-eth1 02069f67-e801-419c-9395-03d4f41ec808 ethernet eth1
bond-slave-eth2 befaaaae-174b-4158-945d-ccd5fb52d058 ethernet eth2
Wired connection 1 b8af1ac4-ff31-3bf2-9265-5fb84a960233 ethernet --
Wired connection 2 e5539525-106f-3b41-8d1b-6cf4823a47ad ethernet --
[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7a:4b:21
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7a:4b:2b
Slave queue ID: 0