Linux下的网络环境的部署
1. IP
1.对于ip的说明
协议名称:tcp/ip
协议版本: ipv4
ip地址:2^32 表示二进制32位
11111111.11111111.11111111.11111111 === 255.255.255.255
11111110.11111110.11111110.11111110 === 254.254.254.254
什么地方:网络位
什么人: 主机位
子网掩玛:可以确定网络范围
ip地址:11111110.11111110.11111110.11111110
11111111.11111111.00000000.00000000==255.255.0.0
254.254.0.1--254.254.254.253 (2^16-2)
那么什么样的两个IP之间可以通信呢?
网络位相同,主机位不同的两个ip可以直接通信
下面我们就做一下有关IP的实验
实验一:关于IP的命令
关于ip的命令
ip addr show | ifconfig 查看ip地址
ping 检测网络通畅
-c 1 只ping一次
-w 1 只等待1秒
设定ip:
ifconfig device ip netmask
ifconfig ens33 172.25.254.11 netmask 255.255.255.0
ip addr add 172.25.254.62/24 dev enp1s0 添加ip
ip addr del dev enp1s0 172.25.254.61/24 删除ip
实验如下:
ip addr show | ifconfig 查看ip地址
ping 检测网络通畅
-c 1 只ping一次
-w 1 只等待1秒
ifconfig device ip netmask
ip addr del dev enp1s0 172.25.254.61/24 删除ip
ip addr add 172.25.254.62/24 dev enp1s0 添加ip
实验二:文件方式更改IP
实验2:文件方式更改ip
1.图形方式:nm-connection-editor
nmtui
2.命令方式:
nmcli device status 查看设备状态
nmcli device disconnect enp1s0 关闭设备
nmcli device connect enp1s0 开启设备
nmcli device modify enp1s0 ip4 172.25.254.161/24 临时添加ip
nmcli connection show 查看网卡信息
nmcli connection down westos 关闭
nmcli connection up westos 开启
nmcli connection modify westos ip4 172.25.254.162 添加ip,添加完成之后必须重启才能生效。
nmcli connection delete westos 删除连接
nmcli connection add con-name westos ifname enp1s0 type ethernet ip4 172.25.254.61/24 添加连接
实验如下:
nm-connection-editor
nmtui
nmcli device status 查看设备状态
nmcli device disconnect enp1s0 关闭设备
nmcli device connect enp1s0 开启设备
nmcli device modify enp1s0 ip4 172.25.254.161/24 临时添加ip
nmcli connection show 查看网卡信息
nmcli connection down westos 关闭
nmcli connection up westos 开启
nmcli connection modify westos ip4 172.25.254.162 添加ip,添加完成之后必须重启才能生效
nmcli connection delete westos 删除连接
nmcli connection add con-name westos ifname enp1s0 type ethernet ip4 172.25.254.61/24 添加连接
文件方式:
配置目录:/etc/sysconfig/network-scripts/
配置文件:ifcfg-任意名称
静态网络:
DEVICE=enp1s0 网卡名称
ONBOOT=yes 网络服务启动网卡激活
BOOTPROTO=none 网卡工作模式
NAME=westos 链接名称
IPADDR=172.25.254.160 IP地址
NETMASK=255.255.255.0 子网掩玛
在rhel8中:
systemctl restart NetworkManager
nmcli connection down westos 原来的链接
nmcli connection up westos 新的链接
实验如下:
2. dhcp服务器的搭建
在rhel8中:
1.配置静态网络
2.把镜像接入光驱
3.df查看光驱挂载位置
4. cd /run/media/root/RHEL-8-0-0-BaseOS-x86_64/BaseOS/Packages/
ls dhcp-*
5.安装dhcp文件
rpm -ivh dhcp-server-4.3.6-30.el8.x86_64.rpm
6.配置dhcp文件
vim /etc/dhcp/dhcp.conf
7.重启服务
systemctl restart dhcpd
实验如下: