1、总结ip分类以及每个分类可以分配的IP数量
它们可唯一标识 IP 网络中的每台设备 ,每台主机(计算机、网络设备、外围设备)必须具有唯一的地 址 IP地址由两部分组成 网络ID:标识网络,每个网段分配一个网络ID,处于高位 主机 ID:标识单个主机,由组织分配给各设备,处于低位 IPv4地址格式:点分十进制记法
共有5类
A类:
0 0000000 - 0 1111111.X.Y.Z : 0-127.X.Y.Z
网络ID位是最高8位,主机ID是24位低位
网络数:126=2^7(可变是的网络ID位数)-2
每个网络中的主机数:2^24-2=16777214
默认子网掩码:255.0.0.0
私网地址:10.0.0.0
范例:114.114.114.114,8.8.8.8,1.1.1.1,58.87.87.99,119.29.29.29
B类:
10 000000 - 10 111111.X.Y.Z:128-191.X.Y.Z
网络ID位是最高16位,主机ID是16位低位
网络数:2^14=16384
每个网络中的主机数:2^16-2=65534
默认子网掩码:255.255.0.0
私网地址:172.16.0.0-172.31.0.0
范例:180.76.76.76,172.16.0.1
C类:
110 0 0000 - 110 1 1111.X.Y.Z: 192-223.X.Y.Z
网络ID位是最高24位,主机ID是8位低位
网络数:2^21=2097152
每个网络中的主机数:2^8-2=254
默认子网掩码:255.255.255.0
私网地址:192.168.0.0-192.168.255.0
范例: 223.6.6.6
D类:组(多)播,1110 0000 - 1110 1111.X.Y.Z: 224-239.X.Y.Z
E类:保留未使用,240-255
2、总结IP配置方法
网络配置方式
动态分配:DHCP: Dynamic Host Configuration Protocol
静态指定: ifconfig, route, netstat ip: object {link, addr, route}, ss, tc system-config-network-tui,setup 配置文件
例如配置静态IP 和更改网卡名称
#修改网卡名称
#设置系统的环境变量加上net.ifnames=0,输入指令,使系统重新加载该环境变量,重启系统后eth0 出现
sed -i.bak -rn '/^GRUB_CMDLINE_LINUX=/s@(.*)"$@\1 net.ifnames=0"@p'
/etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
#实现固定IP
#跳转到/etc/sysconfig/network-scripts/将ens33 改名ifcfg-eth0 然后编辑内容
cd /etc/sysconfig/network-scripts
cp ifcfg-ens33 ifcfg-eth0
sed -i.bak -r -e /^IP/d -e 's/ens33/eth0/' -e '$a IPADDR=10.0.0.208 \n PREFIX=24 \n GATEWAY=10.0.0.201 \n DNS1=10.0.0.201' -e 's/BOOTPROTO=dhcp/BOOTPROTO=static/' ifcfg-eth0
#vim ifcfg-eth0
#1 DEVICE=eth0
#2 NAME=eth0
#3 BOOTPROTO=static
#4 IPADDR=10.0.0.203
#5 PREFIX=24
#6 GATEWAY=10.0.0.201
#7 DNS1=10.0.0.201
#8 ONBOOT=yes
3、使用nmcli实现bonding
[16:44:21 root@bear7 ~]#nmcli con add type bond con-name mybond0 ifname bond0 ipv4.address 192.168.0.110/24 ipv4.gateway 192.168.0.100 mode active-backup
Warning: There is another connection with the name 'mybond0'. Reference the connection by its uuid 'b98c6f99-fcdf-4e4c-9fd0-ea37a035309e'
Connection 'mybond0' (b98c6f99-fcdf-4e4c-9fd0-ea37a035309e) successfully added.
[16:04:14 root@bear7 ~]#nmcli con add type bond-slave ifname eth0 master bond0
Connection 'bond-slave-eth0' (2e74bbbd-97c9-4f38-94a2-59b27ca22cf9) successfully added.
[16:05:19 root@bear7 ~]#nmcli con add type bond-slave ifname eth1 master bond0
Connection 'bond-slave-eth1' (a1fad4f9-9daa-476c-9e9a-81cba62bfff4) successfully added.
[16:05:31 root@bear7 ~]#nmcli con up bond-slave-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/19)
[16:05:37 root@bear7 ~]#nmcli con up bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[16:05:47 root@bear7 ~]#nmcli con up mybond0
[16:59:23 root@bear7 ~]#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,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:d1:a1:40 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:33:11:f1 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:33:11:f1 brd ff:ff:ff:ff:ff:ff
5: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether 00:0c:29:d1:a1:40 brd ff:ff:ff:ff:ff:ff
32: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:d1:a1:40 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.110/24 brd 192.168.0.255 scope global noprefixroute bond0
valid_lft forever preferred_lft forever
inet 10.0.0.219/24 brd 10.0.0.255 scope global noprefixroute dynamic bond0
valid_lft 1458sec preferred_lft 1458sec
inet6 fe80::76fb:a16c:d478:7602/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[16:59:26 root@bear7 ~]#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: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:d1:a1:40
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 2
Permanent HW addr: 00:0c:29:d1:a1:4a
Slave queue ID: 0