目錄
一、實驗拓撲
二、網絡規劃
三、實驗要求
四、環境準備
1.firewall
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
(2)打開firewall路由轉發
2.PC1(內網)
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
3.PC2外網
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
4.服務器
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
(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,s1地址為: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.firewall
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
?
#配置網卡[root@SERVER1 ~]# cd /etc/sysconfig/network-scripts/[root@SERVER1 network-scripts]# vim ifcfg-ens160TYPE=EthernetBOOTPROTO=staticNAME=ens160UUID=e9cd890f-3b47-4859-8c19-3040664051f7DEVICE=ens160ONBOOT=yesIPADDR=192.168.1.254PREFIX=24[root@SERVER1 network-scripts]# vim ifcfg-ens192TYPE=EthernetBOOTPROTO=staticNAME=ens192DEVICE=ens192ONBOOT=yesIPADDR=10.0.0.100PREFIX=8[root@SERVER1 network-scripts]# vim ifcfg-ens224TYPE=EthernetBOOTPROTO=staticNAME=ens224DEVICE=ens224ONBOOT=yesIPADDR=192.168.2.254PREFIX=24 #關閉防火墻 設置selinux[root@SERVER1 network-scripts]# systemctl stop firewalld.service [root@SERVER1 network-scripts]# setenforce 0
(2)打開firewall路由轉發
?[root@SERVER1 network-scripts]# vim /etc/sysctl.conf[root@SERVER1 network-scripts]# sysctl -pnet.ipv4.ip_forward = 1
2.PC1(內網)
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
?#關閉防火墻 設置selinux[root@PC1 network-scripts]# systemctl stop firewalld.service [root@PC1 network-scripts]# setenforce 0#設置網卡[root@PC1 ~]# cd /etc/sysconfig/network-scripts/[root@PC1 network-scripts]# vim ifcfg-ens160TYPE=EthernetBOOTPROTO=staticNAME=ens160DEVICE=ens160ONBOOT=yesIPADDR=192.168.1.1PREFIX=24GATEWAY=192.168.1.254DNS1=192.168.1.254
3.PC2外網
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
?#關閉防火墻 設置selinux[root@PC2 network-scripts]# systemctl stop firewalld.service [root@PC2 network-scripts]# setenforce 0#設置網卡 網關[root@PC2 ~]# cd /etc/sysconfig/network-scripts/[root@PC2 network-scripts]# vim ifcfg-ens160TYPE=EthernetBOOTPROTO=staticNAME=ens160DEVICE=ens160IPADDR=10.0.0.1PREFIX=8GATEWAY=10.0.0.254DNS1=10.0.0.254ONBOOT=yes
4.服務器
(1)配置防火墻各大網卡IP并禁用 firewall和selinux
?#關閉防火墻 設置selinux[root@localhost network-scripts]# systemctl stop firewalld.service [root@localhost network-scripts]# setenforce 0#設置網卡 網關[root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# vim ifcfg-ens160TYPE=EthernetBOOTPROTO=staticNAME=ens160DEVICE=ens160ONBOOT=yesIPADDR=192.168.2.1PREFIX=24GATEWAY=192.168.2.254DNS1=192.168.2.254
(3)下載nginx,并開通服務
?#配置本地源[root@localhost ~]# cd /etc/yum.repos.d/[root@localhost yum.repos.d]# vim local.repo [local]name=localbaseurl=file:///mnt/AppStreamenabled=1gpgcheck=0root@localhost yum.repos.d]# mount /dev/sr0 /mnt/mount: /mnt: WARNING: device write-protected, mounted read-only.mount: (hint) your fstab has been modified, but systemd still usesthe old version; use 'systemctl daemon-reload' to reload.[root@localhost yum.repos.d]# yum install -y nginx
5.環境檢測
(1)內網連接
?[root@PC1 ~]# ping 192.168.2.1PING 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.685 ms?[root@PC1 ~]# ping 10.0.0.100PING 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.639 ms64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.694 ms?[root@localhost ~]# ping 192.168.1.1PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=0.505 ms?[root@localhost ~]# ping 10.0.0.100PING 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.412 ms64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.404 ms
??
(2)外網連接
?[root@localhost network-scripts]# ping 10.0.0.100PING 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.811 ms64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.395 ms?
五、防火墻配置及測試
內部網絡中的pc1采用SNAT訪問外部互聯網,但是無法ping到內部網關。
?#修改iptables 內部網絡通過SNAT,訪問外部網絡[root@SERVER1 ~]# iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP#訪問外網測試[root@SERVER1 ~]# ping 10.0.0.1PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.469 ms64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.408 ms^C--- 10.0.0.1 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1001msrtt min/avg/max/mdev = 0.408/0.438/0.469/0.037 ms#修改iptables 使內網不能訪問網關[root@SERVER1 ~]# iptables -t filter -A INPUT -s 192.168.1.1 -d 192.168.1.254 -p icmp --icmp-type 8 -j DROP[root@PC1 ~]# ping 192.168.1.254PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.#服務器訪問內網[root@localhost ~]# ping 192.168.1.1PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=0.851 ms64 bytes from 192.168.1.1: icmp_seq=2 ttl=63 time=0.822 ms
內部網絡服務器s1通過DNAT發布服務到互聯網。
?#配置nginx[root@localhost yum.repos.d]# systemctl start nginx[root@localhost yum.repos.d]# cd /usr/share/nginx/html/[root@localhost html]# ls404.html 50x.html index.html nginx-logo.png poweredby.png[root@localhost html]# echo c2505 > index.html [root@localhost html]# curl 192.168.2.1c2505?#配置iptables[root@SERVER1 ~]# 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@SERVER1 ~]# iptables -nL -t natChain PREROUTING (policy ACCEPT)target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ? DNAT ? ? ? tcp ?-- ?0.0.0.0/0 ? ? ? ? ? ?10.0.0.100 ? ? ? ? ? tcp dpt:80 to:192.168.2.1#測試[root@localhost ~]# curl 10.0.0.100c2505
互聯網主機pc2能夠
訪問DMZ區域的服務器,但是不能夠進行ping和ssh連接。
?#配置iptables[root@SERVER1 ~]# 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@SERVER1 ~]# iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP[root@SERVER1 ~]# iptables -t filter -A INPUT -p tcp -s 10.0.0.1 --dport 22 -j DROP[root@SERVER1 ~]# iptables -nL Chain INPUT (policy ACCEPT)target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ? DROP ? ? ? icmp -- ?0.0.0.0/0 ? ? ? ? ? ?0.0.0.0/0 ? ? ? ? ? icmptype 8DROP ? ? ? tcp ?-- ?10.0.0.1 ? ? ? ? ? ? 0.0.0.0/0 ? ? ? ? ? tcp dpt:22#測試[root@localhost ~]# curl 10.0.0.100c2505[root@localhost ~]# ssh root@192.168.2.1ssh: connect to host 192.168.2.1 port 22: No route to host[root@localhost ~]# ping 192.168.2.1PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
??