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

验证

相关推荐
一叶龙洲4 小时前
wslg打开Ubuntu24.04默认打开图形界面
linux·服务器·数据库·ubuntu
敖行客 Allthinker6 小时前
Parallels Ubuntu虚拟机项目如何让手机访问?完整解决方案
linux·运维·ubuntu
keyipatience7 小时前
线程栈与TLS和线程互斥
java·linux·服务器·开发语言·ubuntu
元Y亨H7 小时前
生产环境监控与故障应急处理(5-5-5 标准)指南
运维
j7~7 小时前
【Linux】二十二.《Linux 信号机制完全指南:表示、捕捉与处理》
linux·信号处理·volatile·可入重函数·保存信号
观山岳五楼8 小时前
Ubuntu 24 怎么使用Ubuntu 20 的镜像源
linux·运维·ubuntu
m0_715646769 小时前
20260720
linux·arm
寒晓星9 小时前
[linux]线程及多线程
linux·运维
辰痕~9 小时前
物理机装Linux操作系统(Ubuntu为例)
linux·ubuntu
慧一居士9 小时前
Linux如何设置固定的静态ip
运维