IP地址简介与配置

1、总结ip分类以及每个分类可以分配的IP数量

A类:
(1.0.0.0-126.0.0.0)
第一个字节为网络号,后三个字节为主机号。该类IP地址的最前面为“0”,所以地址的网络号取值于1~126之间。一般用于大型网络。
定义:第1字节为网络地址,其它3个字节为主机地址
范围:1.0.0.1-126.255.255.254
数量:允许有126个网段,每个网段允许有16777214台主机
子网掩码:255.0.0.0
私有地址:10.X.X.X是私有地址(所谓的私有地址就是在互联网上不使用,而被用在局域网络中的地址),范围10.0.0.1-10.255.255.254
保留地址:127.X.X.X是保留地址,也是本机地址,等效于localhost或本机IP。一般用于测试使用。例如:ping 127.0.0.1来测试本机TCP/IP是否正常。

B类(128.0.0.0-191.255.0.0)
前两个字节为网络号,后两个字节为主机号。该类IP地址的最前面为“10”,所以地址的网络号取值于128~191之间。一般用于中等规模网络。
定义:第1字节和第2字节为网络地址,其它2个字节为主机地址
范围:128.0.0.1-191.255.255.254
数量:允许有16384个网段,每个网段允许有65534台主机
子网掩码:255.255.0.0
私有地址:172.16.0.0 - 172.31.255.255是私有地址
保留地址:169.254.X.X是保留地址。如果IP地址是自动获取IP地址,而你在网络上又没有找到可用的DHCP服务器。就会得到其中一个IP

C类
(192.0.0.0-223.255.255.0)
前三个字节为网络号,最后一个字节为主机号。该类IP地址的最前面为“110”,所以地址的网络号取值于192~223之间。一般用于小型网络。
定义:第1字节、第2字节和第3个字节为网络地址,第4个个字节为主机地址。另外第1个字节的前三位固定为110
范围:192.0.0.1 - 223.255.255.254
数量:允许有2097152个网段,每个网段允许有254台主机
子网掩码:255.255.255.0
私有地址:192.168.X.X是私有地址。(192.168.0.0 - 192.168.255.255)

D类:
是多播地址。该类IP地址的最前面为“1110”,所以地址的网络号取值于224~239之间。一般用于多路广播用户。
定义:不分网络地址和主机地址,它的第1个字节的前四位固定为1110
范围:224.0.0.1 - 239.255.255.254

E类:
是保留地址。该类IP地址的最前面为“1111”,所以地址的网络号取值于240~255之间。
定义:不分网络地址和主机地址,它的第1个字节的前五位固定为11110
范围:240.0.0.1 - 255.255.255.254

2、总结IP配置方法

ifconfig
  #禁用eth1网卡
  ifconfig eth1 down
  #配置IP地址
  ifconfig eth1 192.168.1.125/24
  #清除IP地址
  ifconfig eth1 0.0.0.0
  #保留原地址虚拟一个新的IP地址2
  ifconfig eth1:2 192.168.1.126/24
  #删除虚拟的地址2
  ifconfig eth1:2 down

ip
 实例
  #修改网卡名为ens33的IP地址为192.168.1.100
  ip addr add 192.168.1.100/24 dev ens33
  #保留原地址虚拟一个新的IP地址2(ip addr add 缩写为ip a a)
  ip a a 192.168.1.101/24 dev ens33 label ens33:1
  #删除一个ens33上的10.10.10.10的IP地址
  ip a d 192.168.1.101/24 dev ens33
  #清除ens33上的所有IP地址
  ip a f dev eth1

3、使用nmcli实现bonding

[root@centos7 ~]#nmcli con add type bond con-name mybond0 ifname bond0 mode active-backup
Connection 'mybond0' (de61af34-fa2a-431a-b5d2-f5e256c35c6a) successfully added.
[root@centos7 ~]#nmcli con add type bond-slave ifname ens37 master bond0
Connection 'bond-slave-ens37' (8a71ef8c-0572-4b5c-9c63-0fcf31e4b053) successfully added.
[root@centos7 ~]#nmcli con add type bond-slave ifname ens38 master bond0
Connection 'bond-slave-ens38' (ae224f95-1c19-495f-8270-896905909ebc) successfully added.
[root@centos7 ~]#nmcli connection up bond-slave-ens37
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[root@centos7 ~]#nmcli connection up bond-slave-ens38
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
[root@centos7 ~]#nmcli connection up mybond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/23)
[root@centos7 ~]#nmcli connection show
NAME                UUID                                  TYPE      DEVICE
mybond0             de61af34-fa2a-431a-b5d2-f5e256c35c6a  bond      bond0
ens33               c96bc909-188e-ec64-3a96-6a90982b08ad  ethernet  ens33
virbr0              0372dfd2-8862-448a-8400-21d65d919d27  bridge    virbr0
bond-slave-ens37    8a71ef8c-0572-4b5c-9c63-0fcf31e4b053  ethernet  ens37
bond-slave-ens38    ae224f95-1c19-495f-8270-896905909ebc  ethernet  ens38
[root@centos7 ~]# 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: ens37
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:e9:62
Slave queue ID: 0

Slave Interface: ens38
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fa:e9:6c
Slave queue ID: 0

[root@centos7 ~]#ifconfig ens37;ifconfig ens38
ens37: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:fa:e9:62  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 2877 (2.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 198  bytes 30346 (29.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens38: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:fa:e9:62  txqueuelen 1000  (Ethernet)
        RX packets 38  bytes 11487 (11.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 5054 (4.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

猜你喜欢

转载自blog.51cto.com/14992172/2595809