一、什么是 IP ADDRESS
- internet protocol ADDRESS ##网络进程地址
- ipv4 internet protocol version 4
- ip是由32个01组成
- 11111110.11111110.11111110.11111110 = 254.254.254.254
- —————————————————————————— ————————
- 网络位 主机位
二、子网掩码
- 用来划分网络区域
- 子网掩码非0的位对应的ip上的数字表示这个ip的网络位
- 子网掩码0位对应的数字是ip的主机位
- 网络位表示网络区域
- 主机位表示网络区域里某台主机
- 11111111.11111111.11111111.00000000 = 255.255.255.0 = 24
- —————————————————————————— ————————
- 网络位 主机位
三、ip通信判定
- 网络位一致,主机位不一致的2个IP可以直接通讯
- 172.25.254.10/24 24=255.255.255.0
- 172.25.254.20/24
- 172.25.0.1/16
- 前两个可以直接通讯,最后一个与其他俩个不能直接通讯
四、网络设定工具 ##临时设定
1.ping ##检测网络是否通畅
- ping ip ##检测网络是否通畅
- ping -c1 ip ##ping 1 次 c代表次数
- ping -w1 ip ##等待1秒 w代表时间
- ping -c1 -w1 ip ##ping1次等待1秒
2.ifconfig ##查看或设定网络接口
- ifconfig ##查看或设定网络接口
- ifconfig ens160 ##查看 ens160的信息
- ifconfig device ip/24 ##设定
- ifconfig device down ##关闭
- ifconfig device up ##开启
3.ip addr ##检测或这顶网络接口
- ip addr ##检测或这顶网络接口
- ip addr show ##检测
- ip addr add ip/24 dev device ##设定
- ip addr del dev ens160 ip/24 ##删除
- ip addr flush ens160 ##刷新ens160的ip地址(删除所有)
- 更改ip步骤
- ip addr flush ens160
- ip addr add dev ens160 172.25.254.10/24
- ip addr show ens160
五、图形方式设定ip ##永久设定
1.设定
- 设定:
- nm-connection-editor
2.更改
- 更改:
- 不建议用服务控制网络
- systemctl restart NetworkManager
- 建议使用:
- nmcli connection show
- nmcli connection down 设置的链接名称 ##关闭ens160
- nmcli connection up 设置的链接名称 ##开启ens160
六、命令方式设定网络
1.NetworkManager必须开启
2. nmcli的用法
<1>nmcli device ##对设备
- nmcli device connect ens160 ##启用ens160网卡
- nmcli device disconnect ens160 ##关闭ens160网卡
- nmcli device show ens160 ##查看网卡信息
- nmcli device status ens160 ##查看网卡服务接口信息
<2>nmcli connection #对连接
- nmcli connection show ##查看连接
- nmcli connection down 设定的连接名称 ##关闭连接
- nmcli connection up 设定的连接名称 ##开启连接
- nmcli connection delete 设定的连接名称 ##删除连接
- 添加连接
- nmcli connection add type ethernet con-name xxxxx ifname ens160 ip4 172.25.254.10/24
- 类型 连接名称 设备名称 地址 ip/子网掩码
更改连接
- nmcli connection modify westos ipv4.addresses 172.25.254.10/24
- nmcli connection down westos ##关闭
- nmcli connection up westos ##开启
七、管理网络配置文件
1.网络配置目录
etc/sysconfig/network-scripts/
2.网络配置文件的名命规则
- vim /etc/sysconfig/network-scripts/ifcfg-xxxx
- DEVICE=ens160 ##设备名称
- BOOTPROTO=dhcp|static|none ##设备工作方式
- ONBOOT=yes ##网络服务开启时自动激活网卡
- IPADDR= ##IP地址
- PREFIX=24 ##子网掩码
- NETMASK=255.255.255.0 ##子网掩码
- NAME= ##接口名称
3.dhcp网络设定
- vim /etc/sysconfig/network-scripts/ifcfg-ens160
- DEVICE=ens160
- ONBOOT=yes
- BOOTPROTO=dhcp
- <1>nmcli connection reload ##保存vim之后 重启连接
- <2>nmcli connection down ens160 ##更改文件后,关闭
- nmcli connection up ens160 ##更改文件后,开启
4.静态网络设定文件
<1>配置单个ip
- vim /etc/sysconfig/network-scripts/ifcfg-ens160
- DEVICE=ens160
- ONBOOT=yes
- IPADDR=172.25.254.100
- NETMASK=255.255.255.0
- BOOTPROTO=none
- NAME=westos
- <1>编辑保存
- nmcli connection reload ##保存vim之后 重启连接
- <2>更改文件
- nmcli connection down ens160 ##更改文件后,关闭
- nmcli connection up ens160 ##更改文件后,开启
<2>一块网卡上配置多个ip
- vim /etc/sysconfig/network-scripts/ifcfg-ens160
- DEVICE=ens160
- ONBOOT=yes
- IPADDR0=172.25.254.100
- NETMASK0=255.255.255.0
- BOOTPROTO=none
- NAME=westos
- IPADDR1=172.25.0.100
- PREFIX1=24
- <1>编辑保存
- nmcli connection reload ##保存vim之后 重启连接
- <2>更改文件
- nmcli connection down ens160 ##更改文件后,关闭
- nmcli connection up ens160 ##更改文件后,开启
- ip addr show ens160
八、dhcp服务配置
1.在双网卡主机中使用镜像找到dhcp-server的安装包
rpm -ivh dhcp-server-4.3.6-30.el8.x86_64.rpm
2.用模板 生成配置文件
-
cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
- ##用模板 生成配置文件
3.修改配置文件
- vim /etc/dhcp/dhcpd.conf
- # dhcpd.conf
- # #
- # Sample configuration file for ISC dhcpd
- #
- # option definitions common to all supported networks...
- option domain-name "westos.com"; ##域名
- option domain-name-servers 114.114.114.114; ##dns
- default-lease-time 600; ##默认租约
- max-lease-time 7200; ##最长租约
- # Use this to enble / disable dynamic dns updates globally.
- #ddns-update-style none;
- # If this DHCP server is the official DHCP server for the local
- # network, the authoritative directive should be uncommented.
- #authoritative;
- #Use this to send dhcp log messages to a different log file (you also
- # have to hack syslog.conf to complete the redirection). log-facility local7;
- # No service will be given on this subnet, but declaring it helps the
- # DHCP server to understand the network topology.
- 27 删除
- 28 删除
- # This is a very basic subnet declaration.
- subnet 172.25.254.0 netmask 255.255.255.0 { ##子网设定
- range 172.25.254.160 172.25.254.200; ##IP地址池
- option routers 172.25.254.250; ##网关
- }
- 39行之后全删除
- [root@carry ~]# systemctl restart dhcpd
- [root@carry ~]# systemctl status dhcpd
- ● dhcpd.service - DHCPv4 Server Daemon
- Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor pres>
- Active: active (running) since Fri 2020-05-08 21:26:42 CST; 1s ago
- Docs: man:dhcpd(8)
- man:dhcpd.conf(5)
- Main PID: 2805 (dhcpd)
- Status: "Dispatching packets..."
- Tasks: 1 (limit: 11380)
- Memory: 8.0M
- CGroup: /system.slice/dhcpd.service
- └─2805 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -grou>
4.测试
- 建立ens160wei DHCP模式
- 在VMware编辑中选择虚拟网络编辑器
- 关闭本地DHCP分配ip服务
- 在Horizon_carry中重启网络服务,可以看到 ip GW dns 全部获取成功
- 在carry中 cat /var/lib/dhcpd/dhcpd.leases 也可以看到Horizon_carry获取成功