目錄
一、網絡規劃
三、環境準備與檢測
1、firewall
(1)配置防火墻各大網卡ip并禁用firewalld和selinux
(2)打開firewall路由轉發
2、PC1(內網)
(1)配置ip并禁用firewalld和selinux
(2)配置網關
3、PC2(外網)
(1)配置ip并禁用firewalld和selinux
4、服務器S1(內網)
(1)配置ip并禁用firewalld和selinux
(2)配置網關
(3)下載nginx,并開通服務
5、環境檢測
(1)內網連接
(2)外網連接
四、防火墻配置及測試
一、網絡規劃
二、主機規劃
-
內部PC1位于內網區域,地址段為: 192.168.1.0/24,pc1地址為:192.168.1.1/24,網關地址為:192.168.1.254/24
-
服務器S1位于服務器區域,地址段為: 192.168.2.0/24,pc1地址為:192.168.2.1/24,網關地址為:192.168.2.254/24
-
PC2位于互聯網區域,模擬外部互聯網,地址段為:10.0.0.0/8,pc2地址為:10.0.0.1/8
-
Linux防火墻的三塊網卡為別連接不同的網絡區域,地址分別為 :ens33 192.168.1.254/24;ens34 10.0.0.100/8;ens35 192.168.2.254/24
三、環境準備與檢測
1、firewall
(1)配置防火墻各大網卡ip并禁用firewalld和selinux
[root@SF1 ~] systemctl stop firewalld.service
[root@SF1 ~] setenforce 0
[root@SF1 ~] ifconfig ens160 192.168.1.254/24
[root@SF1 ~] ifconfig ens192 10.0.0.100/8
[root@SF1 ~] ifconfig ens224 192.168.2.254
(2)打開firewall路由轉發
[root@SF1 ~] sysctl -p
net.ipv4.ip_forward = 1
2、PC1(內網)
(1)配置ip并禁用firewalld和selinux
[root@PC1 ~] systemctl stop firewalld.service
[root@PC1 ~] setenforce 0
[root@PC1 ~] ifconfig ens160 192.168.1.1/24
(2)配置網關
[root@PC1 ~] route add -net 0/0 gw 192.168.1.254
[root@PC1 ~] route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 ens160
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
3、PC2(外網)
(1)配置ip并禁用firewalld和selinux
[root@PC2 ~] systemctl stop firewalld.service
[root@PC2 ~] setenforce 0
[root@PC2 ~] ifconfig ens160 10.0.0.1/8
4、服務器S1(內網)
(1)配置ip并禁用firewalld和selinux
[root@S1 ~] systemctl stop firewalld.service
[root@S1 ~] setenforce 0
[root@S1 ~] ifconfig ens160 192.168.2.1/24
(2)配置網關
[root@S1 ~] route add -net 0/0 gw 192.168.2.254
[root@S1 ~] route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.254 0.0.0.0 UG 0 0 0 ens160
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
(3)下載nginx,并開通服務
[root@S1 yum.repos.d] yum -y install nginx
[root@S1 yum.repos.d] systemctl restart nginx[root@S1 yum.repos.d] echo 2025 > /usr/share/nginx/html/index.html
5、環境檢測
(1)內網連接
[root@PC1 ~] ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=63 time=0.784 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=63 time=0.836 ms[root@PC1 ~] ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_seq=1 ttl=64 time=0.498 ms
64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.689 ms[root@PC1 ~] ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.1.254: icmp_seq=1 ttl=64 time=6.42 ms
64 bytes from 192.168.1.254: icmp_seq=2 ttl=64 time=0.651 ms
(2)外網連接
[root@PC1 ~] ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
^C
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2086ms
##環境搭建之初,內網PC1無法訪問外網PC2
四、防火墻配置及測試
1、內部網絡中的pc1采用SNAT訪問外部互聯網,但是無法ping到內部網關
配置
[root@SF1 ~] iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
[root@SF1 ~] iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP外網測試
[root@PC1 ~] ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=63 time=1.19 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=63 time=0.934 ms內部網關測試
[root@PC1 ~] ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
^C
--- 192.168.1.254 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1007ms
2、內部網絡服務器s1通過DNAT發布服務到互聯網。
[root@SF1 ~] iptables -t nat -A PREROUTING -i ens192 -d 10.0.0.100 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.1[root@PC2 ~] curl 10.0.0.100
2025
3、互聯網主機pc2能夠訪問DMZ區域的服務器,但是不能夠進行ping和ssh連接。
[root@SF1 ~] iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP
[root@SF1 ~] iptables -t filter -A INPUT -p tcp --dport 22 -j DROP[root@PC2 ~] ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.[root@PC2 ~] ssh root@10.0.0.100
ssh: connect to host 10.0.0.100 port 22: Connection timed out