一、IP地址的分类及每类ip可使用的分配数量
1、IP地址分类分为5类,常用的只有A-C类:
A类:1.0.0.0~126.255.255.255 子网掩码:255.0.0.0
B类:128.0.0.0~191.255.255.255 子网掩码:255.255.0.0
C类:192.0.0.0~223.255.255.255 子网掩码:255.255.255.0
D类:224.0.0.0~239.255.255.255
E类:240.0.0.0~255.255.255.254
2、IP地址常用的三类地址所保留可用的私网地址范围:
A类:10.0.0.0~10.255.255.255 子网掩码:255.0.0.0
B类:172.16.0.0~172.31.255.255 子网掩码:255.255.0.0
C类:192.168.0.0~192.168.255.255 子网掩码:255.255.255.0
3、常用IP地址的分类可用地址的计算公式:
每个网络中的主机数=2^主机位-2
常用分类可使用的主机数
A类:2^24-2=16777214
B类:2^16-2=65534
C类:2^8-2=254
4、特殊的IP地址:
0.0.0.0
0.0.0.0不是一个真正意义上的IP地址,它表示所有不清楚的主机和目的网络
255.255.255.255
限制广播地址,对于本机来说,这个地址指本网段内(同一广播域)的所有主机
127.0.0.1~127.255.255.254
本机回环地址,主要用于测试,在介质上永远不应该出现目的地址为127.0.0.1的数据包
244.0.0.0到239.255.255.255
组播地址,244.0.0.1特指所有主机,244.0.0.2特指所有的路由器,244.0.0.5特指OSPF路由器,地址多用于一些特定的程序以及多媒体程序
169.254.×.×
如果windows主机使用了DHCP自动分配IP地址,而又无法从DHCP服务器获取地址,系统会为主机分配这样的地址
二、IP地址常用的配置方法
1、此配置方法临时生效,重启机器此IP地址失效
[21:23:12 root@local_warehouse ~]#ifconfig ens32:1 192.168.10.26 netmask 255.255.255.0
[21:23:39 root@local_warehouse ~]#ifconfig
ens32:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.26 netmask 255.255.255.0 broadcast 192.168.10.255
ether 00:0c:29:4e:a7:b5 txqueuelen 1000 (Ethernet)
[21:25:32 root@local_warehouse ~]#ifconfig ens32:1 down //关闭配置的临时IP地址
2、IP地址永久生效方法:
2.1、更改配置文件
[21:29:17 root@local_warehouse ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=ens32
UUID=6f2405f7-0b0b-4f8e-bfaf-852ac060b811
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.10.24
MASK=255.255.255.0
GATEWAY=192.168.10.1
DNS1=114.114.114.114
[21:31:44 root@local_warehouse ~]#systemctl restart network
[21:32:02 root@local_warehouse ~]#ifconfig ens32
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.24 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe4e:a7b5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4e:a7:b5 txqueuelen 1000 (Ethernet)
RX packets 136827 bytes 185360826 (176.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23481 bytes 2631857 (2.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2.2、centos7、8使用nmcli命令配置IP地址
[21:53:33 root@local_warehouse ~]#nmcli connection modify ens32 ipv4.method manual ipv4.addresses 192.168.10.26/24 connection.autoconnect yes
[21:56:59 root@local_warehouse ~]#nmcli connection up ens32
[22:00:37 root@local_warehouse ~]#ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.26 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe4e:a7b5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4e:a7:b5 txqueuelen 1000 (Ethernet)
RX packets 140017 bytes 185655334 (177.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26017 bytes 2948787 (2.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2.3、使用nmtui命令调用图形界面配置IP地址和主机名称(基于NetworkManager)
(过程略)
三、实现多网卡的绑定
环境准备:系统centos7,含有两张网卡,此实验使用ens34和ens35来实现网卡的绑定
[22:21:05 root@local_warehouse ~]#nmcli connection show
NAME UUID TYPE DEVICE
ens32 6f2405f7-0b0b-4f8e-bfaf-852ac060b811 ethernet ens32
ens34 07f76db3-e608-4a90-a39b-cf93203a029b ethernet ens34
ens35 d47a5a48-7018-403d-9538-7e5f8aedb71c ethernet ens35
#添加bonding接口
nmcli con add type bond con-name mybond0 ifname bond0 mode active-backup
#添加从属接口
nmcli con add type bond-slave ifname ens34 master bond0
nmcli con add type bond-slave ifname ens35 master bond0
#要启动绑定,则必须首先启动从属接口
nmcli con up bond-slave-ens34
nmcli con up bond-slave-ens35
#启动绑定
nmcli con up mybond0
#网络组:
[22:47:32 root@local_warehouse ~]#nmcli connection add type team ifname team0 con-name team0 ipv4.method manual ipv4.addresses 192.168.10.31/24 ipv4.gateway 192.168.10.1 config '{"runner":{"name":"activebackup"}}'
[22:55:09 root@local_warehouse ~]#nmcli connection add type team-slave con-name team0-1 ifname ens34 master team0
Connection 'team0-1' (130f3efc-d932-493e-a033-21cd669e932c) successfully added.
[22:55:18 root@local_warehouse ~]#nmcli connection add type team-slave con-name team0-2 ifname ens35 master team0
Connection 'team0-2' (d52fe597-a6e4-4d79-9ce5-67dde9d1ee92) successfully added.
[22:55:28 root@local_warehouse ~]#nmcli connection up team0-1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/45)
[22:55:47 root@local_warehouse ~]#nmcli connection up team0-2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/46)
[22:55:50 root@local_warehouse ~]#nmcli connection up team0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/47)
[22:55:54 root@local_warehouse ~]#ifconfig team0
team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.31 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::792b:f058:6d6f:e131 prefixlen 64 scopeid 0x20<link>
inet6 fe80::94bb:f3f9:8c2c:f6ee prefixlen 64 scopeid 0x20<link>
inet6 fe80::59d2:253d:2a97:cf3d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4e:a7:bf txqueuelen 1000 (Ethernet)
RX packets 8 bytes 476 (476.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 2082 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试:断掉其中的任意一张网卡网络还是通的
[c:\~]$ ping 192.168.10.31 -t
正在 Ping 192.168.10.31 具有 32 字节的数据:
来自 192.168.10.1 的回复: 无法访问目标主机。
来自 192.168.10.31 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.10.31 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.31 的回复: 字节=32 时间<1ms TTL=64