linux下的网络环境部署(上)

#####1.IP###################

IP说明:inter proto adress

协议名称: tcp/ip

协议版本: ipv4

IP地址:2^32(二进制的32)

11111111.11111111.11111111.11111111   ==  255.255.255.255

什么地方:网络位

什么人:主机位

子网掩码:

ip地址:

11111110.11111110.11111110.111111110

扫描二维码关注公众号,回复: 9191106 查看本文章

11111111.11111111.0000000.00000000 == 255.255.0.0

地址范围:254.254.0.1~254.254.254.253

什么样的两个IP可以通信:

网络位相同   主机位不同的两个IP是可以直接通信的

172.25.254.1/24    =172.25.254.1/255.255.255.0

实验一:关于IP的命令

[root@rhel7 ~]# ip addr show   ##查看IP地址(ifconfig也可以)

[root@rhel7 ~]# ifconfig ens33 192.168.3.109 netmask 255.255.255.0    ##临时设定IP

[root@rhel8 ~]# ifconfig    ##查看rhel8地址

[root@rhel7 ~]# ping 192.168.3.209  ##ping rhel8

[root@rhel7 ~]# ping -c1 192.168.3.209   ##ping一次

[root@rhel7 ~]# ping -w1 -c1 192.168.3.209    ##等待1秒

[root@rhel7 ~]# ip addr show   ##查看ip地址

[root@rhel7 ~]# ip addr del dev ens33 192.168.3.109/24   ##删除ip地址

[root@rhel7 ~]# ip addr add 192.168.3.109/24 dev ens33     ##添加IP

实验二:文件方式更改ip

图形方式:

 nm-connection-editor

[root@rhel7 ~]# systemctl status NetworkManager  ##开启服务

[root@rhel7 ~]# nm-connection-editor

[root@rhel7 ~]# ifconfig  ##查看IP

命令方式:

[root@rhel7 ~]# nmcli device status  ##查看设备状态

[root@rhel7 ~]# nmcli device disconnect ens33  ##关闭设备

[root@rhel7 ~]# nmcli device connect ens33     ##开启设备

[root@rhel7 ~]# nmcli connection show    ##查看网卡信息

[root@rhel7 ~]# nmcli connection down westos     ##关闭

[root@rhel7 ~]# nmcli connection up westos    ##开启

[root@rhel7 ~]# nmcli connection modify westos ip4 192.168.3.10/24   ##添加ip添加完成后必须重启连接才能生效

[root@rhel7 ~]# nmcli connection delete westos   ##删除连接

[root@rhel7 ~]# nmcli connection add con-name westos ifname ens33 type ethernet ip4 192.168.3.109/24   ##添加连接

[root@rhel7 ~]# nmcli connection add con-name westos ifname ens33 type ethernet ipv4.method auto     ##添加dhcp网路

文件方式:

配置目录:/etc/sysconfig/network-scripts/

配置文件:ifcfg-任意名称

1.dhcp:

[root@rhel7 ~]# nmcli connection delete westos  ##删除已有的连接

 [root@rhel7 network-scripts]# vim ifcfg-ens33  ##编写网卡配置文件

DEVICE=ens33              ##网卡名称 
ONBOOT=yes                ##网络服务启动网卡激活
BOOTPROTO=dhcp      ##网卡工作模式为dhcp
NAME=westos               ##连接名称为westos

在rhel7中:

[root@rhel7 network-scripts]# systemctl restart network     ##重启服务

在rhel8中:(同下静态网络)

静态网络:

[root@rhel7 network-scripts]# vim ifcfg-ens33

DEVICE=ens33                         ##网卡名称
ONBOOT=yes                          ##网络服务启动网卡激活
BOOTPROTO=none                ##网卡工作模式
NAME=westos                         ##连接名称为westos
IPADDR=192.168.3.109          ##IP地址
NETMASK=255.255.255.0      ##子网掩码

在rhel7中:

[root@rhel7 network-scripts]# systemctl restart network    ##重启网络

在rhel8中:

[root@rhel8 network-scripts]# vim ifcfg-westos  ##编写文件

[root@rhel8 network-scripts]# systemctl restart NetworkManager   ##重启服务

[root@rhel8 network-scripts]# nmcli connection show  ##查看是否生效(没生效)

[root@rhel8 network-scripts]# nmcli connection down ens160   ##关闭ens160

[root@rhel8 network-scripts]# nmcli connection up westos    ##开启westos

[root@rhel8 network-scripts]# ifconfig  ##查看

#####2.dhcp服务器的搭建#########################

在rhel8中:

1.配置静态网络

2.把镜像接入光驱

3.df查看光驱挂载位置

[root@rhel8 network-scripts]# df

4.

[root@rhel8 network-scripts]# cd /run/media/root/RHEL-8-0-0-BaseOS-x86_64/    ##进入目录

[root@rhel8 RHEL-8-0-0-BaseOS-x86_64]# cd BaseOS/  ##进入BaseOS

[root@rhel8 BaseOS]# cd Packages/    ##进入Packages

[root@rhel8 Packages]# ls dhcp-*   

   

5.安装dhcp

[root@rhel8 Packages]# rpm -ivh dhcp-server-4.3.6-30.el8.x86_64.rpm

[root@rhel8 Packages]# cd /etc/sysconfig/network-scripts/   ##进入目录

[root@rhel8 network-scripts]# rm -fr ifcfg-westos  ##删除文件

[root@rhel8 network-scripts]# vim ifcfg-ens160   ##编辑文件

[root@rhel8 network-scripts]# systemctl restart NetworkManager  ##重启网络

6.配置dhcp文件

[root@rhel8 ~]# cd /etc/dhcp/    ##进入配置目录

[root@rhel8 dhcp]# vim dhcpd.conf   ##编辑文件 (一开始为空告诉了模板路径)

[root@rhel8 dhcp]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example   /etc/dhcp/dhcpd.conf      ##复制文件

[root@rhel8 dhcp]# vim dhcpd.conf   ##编辑文件

  7 option domain-name "westos.com";                      ##域名设定
  8 option domain-name-servers 114.114.114.114;    ##dns

删除原有的27,28行

36行以下全部删除

编辑原来的第32,33,34行(现在是30-32   30.设定网段   31.分配地址范围    32.网关)

7.重启服务

[root@rhel8 dhcp]# systemctl restart dhcpd
[root@rhel8 dhcp]# systemctl status dhcpd

8.测试

rhel7中配置dhcp网络看是否可以获得ip

在rhel7中查看网卡的物理硬件地址

[root@rhel7 ~]# cd /etc/sysconfig/network-scripts/    ##进入目录

[root@rhel7 network-scripts]# vim ifcfg-ens33  ##编辑文件

[root@rhel7 network-scripts]# systemctl restart network       ##重启网路服务

在rhel8中查看ip分配情况

[root@rhel8 dhcp]# cat /var/lib/dhcpd/dhcpd.leases

注意:

lease 192.168.3.100 {                                     ##分配出去的IP

hardware ethernet 00:0c:29:42:57:18;            ##获取此ip的网卡硬件地址

在rhel7中的dhcp的安装如下:

[root@rhel7 network-scripts]# df

[root@rhel7 network-scripts]# cd "/run/media/root/RHEL-7.6 Server.x86_64"      ##进入目录

[root@rhel7 RHEL-7.6 Server.x86_64]# cd Packages/  ##进入目录

[root@rhel7 Packages]# rpm -ivh dhcp-4.2.5-68.el7_5.1.x86_64.rpm   ##安装此软件

发布了11 篇原创文章 · 获赞 0 · 访问量 153

猜你喜欢

转载自blog.csdn.net/weixin_46102303/article/details/104328403