目錄
實驗環境
實踐要求
一、準備工作
1、準備四臺虛擬機,分別標號
2、 防火墻額外添加兩塊網卡,自定義網絡連接模式
3、 關閉虛擬機的圖形管理工具
4、關閉防火墻
?5、分別配置四臺虛擬機的IP地址,此處舉一個例子(使用的臨時分配地址)
?6、開啟防火墻路由轉發功能并驗證
7、配置內網機和服務器的網關地址
8、?給服務器安裝nginx服務
9、測試各個主機之間的連接情況
?二、內部網絡中的pc1采用SNAT訪問外部互聯網,但是無法ping到內部網關。
三、內部網絡服務器s1通過DNAT發布服務到互聯網。
四、互聯網主機pc2能夠訪問DMZ區域的服務器,但是不能夠進行ping和ssh連接。
實驗環境
-
內部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
?
實踐要求
-
內部網絡中的pc1采用SNAT訪問外部互聯網,但是無法ping到內部網關。
-
內部網絡服務器s1通過DNAT發布服務到互聯網。
-
互聯網主機pc2能夠訪問DMZ區域的服務器,但是不能夠進行ping和ssh連接。
一、準備工作
1、準備四臺虛擬機,分別標號
2、 防火墻額外添加兩塊網卡,自定義網絡連接模式
3、 關閉虛擬機的圖形管理工具
systemctl stop NetworkManager
4、關閉防火墻
systemctl stop firewalld.service
?5、分別配置四臺虛擬機的IP地址,此處舉一個例子(使用的臨時分配地址)
ifconfig ens160 192.168.1.1/24
?6、開啟防火墻路由轉發功能并驗證
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
7、配置內網機和服務器的網關地址
route add -net 0/0 gw 192.168.1.254 dev ens160
route add -net 0/0 gw 192.168.2.254 dev ens160
8、?給服務器安裝nginx服務
配置本地倉庫源后安裝nginx
yum -y install nginx
echo "hello!" > /usr/share/nginx/html/index.html
9、測試各個主機之間的連接情況
- 測試內網機和防火墻的通聯性
[root@localhost network-scripts]# ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.2.254: icmp_seq=1 ttl=64 time=0.453 ms
- 測試服務器和防火墻的通聯性
[root@localhost network-scripts]# ping 192.168.2.254
PING 192.168.2.254 (192.168.2.254) 56(84) bytes of data.
64 bytes from 192.168.2.254: icmp_seq=1 ttl=64 time=0.273 ms
64 bytes from 192.168.2.254: icmp_seq=2 ttl=64 time=0.266 ms
^X^C
- ?測試內網機和服務器的通聯性
[root@nei ~]# 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=64 time=18.2 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=5.04 ms
^C
- 外網機沒有網關地址,所以和其他三臺主機之間必然不通
二、內部網絡中的pc1采用SNAT訪問外部互聯網,但是無法ping到內部網關。
- ?在防火墻上書寫規則
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ens256 -j MASQUERADE
iptables -A INPUT -s 192.168.1.1 -d 192.168.1.254 -p icmp --icmp-type 8 -j DROP
- 驗證
##內網機ping外網機
[root@nei ~]# 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=36.6 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=63 time=4.72 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=63 time=8.38 ms
^C
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
rtt min/avg/max/mdev = 4.715/16.549/36.550/14.221 ms##內網機ping內部網關
[root@nei ~]# 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 ---
6 packets transmitted, 0 received, 100% packet loss, time 5117ms
三、內部網絡服務器s1通過DNAT發布服務到互聯網。
- ?在防火墻上書寫規則
iptables -t nat -A POSTROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.2.1
- ?驗證
##外網機訪問服務器
[root@wai ~]# curl 10.0.0.100
hello!
四、互聯網主機pc2能夠訪問DMZ區域的服務器,但是不能夠進行ping和ssh連接。
- ?在防火墻上書寫規則
iptables -A FORWARD -p tcp -s 10.0.0.1 -d 192.168.2.1 --dport 22 -j DROP
iptables -A FORWARD -i ens256 -o ens224 -d 192.168.2.0/24 -p icmp --icmp-type 8 -j DROP
- 驗證
##測試ssh遠程連接服務器主機
[root@wai ~]# ssh root@10.0.0.100
ssh: connect to host 10.0.0.100 port 22: Connection timed out##測試ping服務器主機
[root@wai ~]# ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
^C
--- 10.0.0.100 ping statistics ---
21 packets transmitted, 0 received, 100% packet loss, time 20470ms