RHCE 防火墙实验

实验一iptables 的源地址转换

第一步

三台设备

1.设备一(server):nat模式 192.168.10.100(nat主机)

2.设备二(route):nat模式 192.168.10.200仅主机 192.168.126.200(路由器)

3.设备三(hostname):仅主机模式 192.168.126.100(hostonly主机)

设备二

上再添加一张网卡,一张是nat模式一张是仅主机模式


​现在来设置一下仅主机模式的网卡

bash 复制代码
[root@clinet ~]# nmcli connection add type ethernet ifname ens224 ipv4.method manual ipv4.addresses 192.168.126.200/24     
[root@clinet ~]# nmcli connection modify ethernet-ens224 ipv4.gateway 192.168.126.2
[root@clinet ~]# nmcli connection modify ethernet-ens224 ipv4.dns 8.8.8.8
[root@clinet ~]# nmcli connection  up ethernet-ens224 

设备三

bash 复制代码
[root@server002 ~]# nmcli connection modify ens160 ipv4.addresses 192.168.126.100/24
[root@server002 ~]#nmcli connection modify ens160  ipv4.gateway 192.168.126.2

[root@server002 ~]#nmcli connection modify ens160 ipv4.dns 8.8.8.8

[root@server002 ~]#nmcli connection up ens160

第二步将路由器的内核转发功能开启

bash 复制代码
​
#将路由器内核转发功能开起
[root@client ~]#echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

#加载配置文件
[root@client ~]#sysctl -p 

#查看系统内核的 IP 转发功能是否开启
[root@client ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0

​

第三步子啊路由器上设置源地址伪装

bash 复制代码
#在路由器上设置源地址伪装
[root@client ~]#iptables -t nat -A POSTROUTING -o ens224 -j SNAT --to-source 111.222.111.222

第四步将设备一的网关设置为192.168.10.200,将设备三的网关设置为192.168.126.200

第五步使用nat主机连接hostonly主机 查看自己的ip是什么

bash 复制代码
[root@server ~]#ssh root@192.168.126.100
[root@server002 ~]# w -i

实验二iptables 目标地址转换

第一步

在路由器上添加规则 将ssh到192.168.10.200流量转移到192.168.126.100

bash 复制代码
[root@client ~]#iptable -t nat -A PREROUTING -i ens160 -j DNAT --to-dest 192.168.111.100​

第二步

远程链接验证是否目标转换

bash 复制代码
[root@server ~]# ssh root@192.168.10.200

[root@server ~]# ip a

实验三firewalld 端口转发

第一步开启伪装

bash 复制代码
​​​​​​​[root@client ~]#firewall-cmd --add-masquerade 

第二步在 firewalld 防火墙中配置 SSH 端口转发

bash 复制代码
[root@client ~]# firewall-cmd --add-forward-port=port=22:proto=tcp:toport=22:toaddr=192.168.126.100

验证

相关推荐
深紫色的三北六号6 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash10 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI20 小时前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing2 天前
WSL+Cpp开发环境配置
linux
蝎子莱莱爱打怪3 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀3 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应3 天前
vi编辑器使用
linux·后端·操作系统
何中应3 天前
Linux进程无法被kill
linux·后端·操作系统
何中应3 天前
rm-rf /命令操作介绍
linux·后端·操作系统