Linux相关知识的第九回合

Linux相关知识的第九回合

就业班及全程班
1、总结ip分类以及每个分类可以分配的IP数量
2、总结IP配置方法
3、使用nmcli实现bonding

架构师班
1、Nginx的作用
2、使用Nginx的优势点

网络相关知识过招

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

A类地址
地址范围 0.0.0.0-127.255.255.255
网络数量 126(0和127不能使用)
可分配的ip数量 16777214
默认子网掩码 255.0.0.0
私有地址 10.0.0.0/8
B类地址
地址范围 128.0.0.0-191.255.255.255
网络数量 214
可分配的ip数量 65534
默认子网掩码 255.255.0.0
私有地址 172.16.0.0/12(172.16.0.0 - 172.31.0.0)
C类地址
地址范围 192.0.0.0-223.255.255.255
网络数量 2097152
可分配的ip数量 254
默认子网掩码 255.255.255.0
私有地址 192.168.0.0/16(192.168.0.0 - 192.168.255.0)
D类地址 组播地址
地址范围 224.0.0.0-239.255.255.255
E类地址 保留地址

总结IP配置方法

IP地址配置可分为动态分配(需要DHCP服务的支持)或者静态指定(指定具体的IP地址)
Linux系统中,配置静态的IP地址的方法

# 永久生效
## 通过修改配置文件,然后重启网络服务
cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=0cf2f360-6860-4cd2-924d-545726fde4e5
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.168.66
PREFIX=24
GATEWAY=192.168.168.254
DNS1=223.5.5.5
IPV6_PRIVACY=no
systemctl restart network.service

# 临时生效
# 清除eth1网卡IP地址
ifconfig eth1 0.0.0.0 
# 添加eth1网卡的IP地址为192.168.168.68/24
ifconfig eth1 192.168.168.68/24

# 修改网卡名称为eth0的IP地址为172.16.0.65/24
ip addr add 172.16.0.65/24 dev eth0
# 清除eth1上的所有IP地址
ip a f dev eth1

使用nmcli实现bonding

[hooper@magedu-demo ~] $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.168.66  netmask 255.255.255.0  broadcast 192.168.168.255
        ether 52:54:00:ed:e8:61  txqueuelen 1000  (Ethernet)
        RX packets 468  bytes 39000 (38.0 KiB)
        RX errors 0  dropped 27  overruns 0  frame 0
        TX packets 75  bytes 8191 (7.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:1a:39:8b  txqueuelen 1000  (Ethernet)
        RX packets 395  bytes 29956 (29.2 KiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 14  bytes 2180 (2.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:c2:2e:c6  txqueuelen 1000  (Ethernet)
        RX packets 395  bytes 29956 (29.2 KiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 13  bytes 1838 (1.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:fe:06:d9  txqueuelen 1000  (Ethernet)
        RX packets 396  bytes 30298 (29.5 KiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 13  bytes 1838 (1.7 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
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 44  bytes 3732 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 44  bytes 3732 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# 添加bonding接口
[hooper@magedu-demo ~] $ nmcli con add type bond con-name hooperbond0 ifname bond0 mode active-backup
Connection 'hooperbond0' (85fa80df-0e66-4e16-a0a4-a55332ead8da) successfully added.
# 添加从属接口
[hooper@magedu-demo ~] $ nmcli con add type bond-slave ifname eth1 master bond0
Connection 'bond-slave-eth1' (a899a147-f5c8-4378-a4ed-17033625bb3e) successfully added.
[hooper@magedu-demo ~] $ nmcli con add type bond-slave ifname eth2 master bond0
Connection 'bond-slave-eth2' (e078e63b-1322-47d5-82ec-2e2761c249da) successfully added.
# 注:如无为从属接口提供连接名,则该名称是接口名称加类型构成
# 要启动绑定,则必须首先启动从属接口
[hooper@magedu-demo ~] $ nmcli con up bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)
[hooper@magedu-demo ~] $ nmcli con up bond-slave-eth2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
# 启动绑定
[hooper@magedu-demo ~] $ nmcli con up hooperbond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
[hooper@magedu-demo ~] $ ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet6 fe80::2147:a625:1f4a:745e  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:c2:2e:c6  txqueuelen 1000  (Ethernet)
        RX packets 1010  bytes 76546 (74.7 KiB)
        RX errors 0  dropped 36  overruns 0  frame 0
        TX packets 28  bytes 3336 (3.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.168.66  netmask 255.255.255.0  broadcast 192.168.168.255
        ether 52:54:00:ed:e8:61  txqueuelen 1000  (Ethernet)
        RX packets 4509  bytes 367836 (359.2 KiB)
        RX errors 0  dropped 140  overruns 0  frame 0
        TX packets 319  bytes 35181 (34.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 52:54:00:c2:2e:c6  txqueuelen 1000  (Ethernet)
        RX packets 3991  bytes 315962 (308.5 KiB)
        RX errors 0  dropped 46  overruns 0  frame 0
        TX packets 90  bytes 13796 (13.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 52:54:00:c2:2e:c6  txqueuelen 1000  (Ethernet)
        RX packets 4012  bytes 319168 (311.6 KiB)
        RX errors 0  dropped 46  overruns 0  frame 0
        TX packets 68  bytes 10528 (10.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:fe:06:d9  txqueuelen 1000  (Ethernet)
        RX packets 4023  bytes 320354 (312.8 KiB)
        RX errors 0  dropped 47  overruns 0  frame 0
        TX packets 58  bytes 9404 (9.1 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
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 44  bytes 3732 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 44  bytes 3732 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[hooper@magedu-demo ~] $ nmcli connection
NAME                UUID                                  TYPE      DEVICE
bond-slave-eth1     a899a147-f5c8-4378-a4ed-17033625bb3e  ethernet  eth1
bond-slave-eth2     e078e63b-1322-47d5-82ec-2e2761c249da  ethernet  eth2
eth0                0cf2f360-6860-4cd2-924d-545726fde4e5  ethernet  eth0
hooperbond0         85fa80df-0e66-4e16-a0a4-a55332ead8da  bond      bond0
Wired connection 1  1722d2ec-3ea3-3b17-bd00-d16d06baf077  ethernet  --
Wired connection 2  addea391-8727-30d2-bc28-dae14cb0ea06  ethernet  --
Wired connection 3  9ff9fecb-dd27-3942-9004-5033de4e430a  ethernet  --
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值