第九周学习
一、总结ip分类以及每个分类可以分配的IP数量
IP地址由两部分组成
网络ID:标识网络,每个网段分配一个网络ID,处于高位
主机 ID:标识单个主机,由组织分配给各设备,处于低位
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
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
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
D类:组(多)播,1110 0000 - 1110 1111.X.Y.Z : 224-239.X.Y.Z
E类:保留未使用,240-255
二、总结IP配置方法
将Linux主机接入到网络,需要配置网络相关设置
一般包括如下内容:
主机名
IP/netmask
路由:默认网关
DNS服务器
主DNS服务器
次DNS服务
网络配置方式
静态指定:
ifconfig, route, netstat
ip: object {link, addr, route} { COMMAND | help }
system-config-network-tui,setup
配置文件: /etc/sysconfig/network-scripts/ifcfg-IFACE
BOOTPROTO: 激活此设备时使用的地址配置协议,常用的dhcp, static, none, bootp
IPADDR 指明IP地址
NETMASK 子网掩码,如:255.255.255.0
PREFIX 网络ID的位数, 如:24(NETMASK和PREFIX二选一)
GATEWAY 默认网关
DNS1 第一个DNS服务器地址
DNS2 第二个DNS服务器地址
动态分配:DHCP: Dynamic Host Configuration Protocol
Ubuntu网卡配置
配置自动获取IP
root@ubuntu1804:~# cat /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: yes
配置静态IP
root@ubuntu1804:~#vim /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [192.168.88.10/24] #或者用下面一行,两种格式不能混用
- 192.168.88.10/24
gateway4: 192.168.88.2
nameservers:
search: [blaine.com]
addresses: [61.128.128.68, 114.114.114.114]
三、使用nmcli实现bonding
[root@centos7 ~]# nmcli con add type bond con-name mybond0 ifname bond0 mode active-backup
Connection 'mybond0' (1be9c885-e9ff-49d8-aa8c-3575b01ded9e) successfully added.
[root@centos7 ~]# nmcli con add type bond-slave ifname eth0 master bond0
Connection 'bond-slave-eth0' (501b3da9-75cf-4faf-a347-bba188007011) successfully added.
[root@centos7 ~]# nmcli con add type bond-slave ifname eth1 master bond0
Connection 'bond-slave-eth1' (897533fb-133c-43d6-bcde-eadebad35414) successfully added.
[root@centos7 ~]# nmcli con up bond-slave-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@centos7 ~]# nmcli con up bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@centos7 ~]# nmcli con up mybond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@centos7 ~]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 192.168.88.132 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::8ace:2c33:1288:ca02 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:34:aa:4b txqueuelen 1000 (Ethernet)
RX packets 124 bytes 9042 (8.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 41 bytes 3878 (3.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:34:aa:4b txqueuelen 1000 (Ethernet)
RX packets 1508 bytes 119301 (116.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 582 bytes 77300 (75.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:34:aa:4b txqueuelen 1000 (Ethernet)
RX packets 210 bytes 15173 (14.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 4010 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 140 (140.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 140 (140.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

浙公网安备 33010602011771号