文章目錄
環境拓撲
需求描述
1、 網關服務器連接互聯網網卡ens33地址爲100.1.1.10,爲公網IP地址,分配到firewall的external區域;連接內網網卡ens36地址爲192.168.1.2,分配到firewall的trusted區域;連接服務器網卡ens37地址爲192.168.2.2,分配到firewall的dmz區域
2、 網站服務器和網關服務器均通過SSH來遠程管理,爲了安全,將SSH默認端口改爲12345
3、 網站服務器開啓 HTTPS,過濾未加密的HTTP流量
4、 網站務器拒絕ping,網關服務器拒絕來自互聯網上的ping
5、 公司內網用戶需要通過網關服務器共享上網
6、 互聯網用戶需要訪問網站服務器
虛擬機試驗環境搭建:
1、 打開虛擬機網絡編輯器
2、 添加對應的網段
一、環境配置
1、網關服務器開啓路由轉發功能
[root@gateway ~]# vim /etc/sysctl.conf //永久生效
net.ipv4.ip_forward = 1
[root@gateway ~]# sysctl -p //生效
2、網站服務器
1) 檢查路由
[root@web ~]# route -n
2)檢查防火牆必須開啓
[root@web ~]# systemctl status firewalld.service
3) 搭建yum
#掛載光盤
[root@web ~]# vim /etc/fstab
/dev/cdrom /mnt iso9660 defaults 0 0
[root@web ~]# mount -a
#搭建yum倉庫
[root@web ~]# cd /etc/yum.repos.d/
[root@web yum.repos.d]# mkdir back
[root@web yum.repos.d]# mv C* back/
[root@web yum.repos.d]# vim local.repo
[centos]
name=centos
baseurl=file:///mnt
gpgcheck=0
enabled=1
[root@web yum.repos.d]# yum clean all
[root@web yum.repos.d]# yum makecache
4)安裝HTTP 安裝https模塊
[root@web yum.repos.d]# yum -y install httpd mod_ssl
[root@web yum.repos.d]# systemctl start httpd //開啓服務
[root@web yum.repos.d]# systemctl enable httpd
#編輯站點內容
[root@web yum.repos.d]# vim /var/www/html/index.html
<h1>hello-kgc<h1>
#測試正常
5)更改ssh端口
[root@web yum.repos.d]# setenforce 0 //關閉核心防護
[root@web yum.repos.d]# vim /etc/sysconfig/selinux
SELINUX=disabled
[root@web yum.repos.d]# vim /etc/ssh/sshd_config //更改端口號
Port 12345
二、防火牆配置
1、在網站服務器上配置防火牆
1) 設置默認區域爲DMZ
[root@web ~]# firewall-cmd --set-default-zone=dmz
2)爲DMZ區域打開https服務添加TCP爲12345端口
[root@web ~]# firewall-cmd --zone=dmz --add-service=https --permanent
[root@web ~]# firewall-cmd --zone=dmz --add-port=12345/tcp --permanent
3)配置dmz區域移除ssh服務
[root@web ~]# firewall-cmd --zone=dmz --remove-service=ssh --permanent
4)禁止ping
[root@web ~]# firewall-cmd --add-icmp-block=echo-request --zone=dmz --permanent
5)重新加載防火牆
[root@web ~]# firewall-cmd --reload
2、網關服務器配置防火牆
1) 檢查下防火牆
[root@gateway ~]# systemctl status firewalld.service
2)設置默認區域external區域
[root@gateway ~]# firewall-cmd --set-default-zone=external
[root@gateway ~]# firewall-cmd --list-all
external (active)
target: default
icmp-block-inversion: no
interfaces: ens33 ens36 ens37
sources:
services: ssh
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
3)設置ens36網卡爲trusted區域;ens37網卡設置爲DMZ區域
[root@gateway ~]# firewall-cmd --change-interface=ens36 --zone=trusted
[root@gateway ~]# firewall-cmd --change-interface=ens37 --zone=dmz
4)查看配置詳情
[root@gateway ~]# firewall-cmd --get-active-zones
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-1aZyehwz-1586700423271)(1586500732485.png)]
5)在企業內網測試訪問網站服務器
打開瀏覽器輸入https://192.168.2.10
6)更改ssh端口號
[root@gateway ~]# setenforce 0 //關閉核心防護
[root@gateway ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
[root@gateway ~]# vim /etc/ssh/sshd_config //更改端口號
Port 12345
7)配置external區域添加TCP12345端口
[root@gateway ~]# firewall-cmd --zone=external --add-port=12345/tcp --permanent
8)配置external區域移除ssh服務
[root@gateway ~]# firewall-cmd --zone=external --remove-service=ssh --permanent
9)配置external禁止ping
[root@gateway ~]# firewall-cmd --zone=external --add-icmp-block=echo-request --permanent
10)重新加載防火牆
[root@gateway ~]# firewall-cmd --reload
11)測試
在Internet外網web服務器上ssh登錄網關服務器的外部接口ens33地址的12345端口
[root@internet ~]# ssh -p 12345 100.1.1.10
12)在企業內部測試機上ssh登錄網站服務器的12345端口
[root@nb ~]# ssh -p 12345 192.168.2.10
3、企業內網訪問外網web服務器
企業內網用戶通過網關服務器能訪問Internet外網web服務器
1) 在外網服務器上搭建HTTP服務
#掛載光盤
[root@internet ~]# vim /etc/fstab
[root@internet ~]# iso9660 defaults 0 0
[root@internet ~]# mount -a
#搭建yum倉庫
[root@internet ~]# cd /etc/yum.repos.d/
[root@internet yum.repos.d]# mkdir back
[root@internet yum.repos.d]# mv C* back/
[root@internet yum.repos.d]# vim local.repo
[centos]
name=centos
baseurl=file:///mnt
gpgcheck=0
enabled=1
[root@internet yum.repos.d]# yum clean all
[root@internet yum.repos.d]# yum makecache
#安裝HTTP服務並啓動
[root@internet yum.repos.d]# yum -y install httpd
[root@internet yum.repos.d]# systemctl start httpd
[root@internet yum.repos.d]# systemctl enable httpd
2)訪問測試
① web外網服務器訪問測試http服務
② 企業內部網站服務器訪問外部web網站
③ 企業內部訪問測試
3)在網關服務器上查看是否開啓僞裝
[root@gatway ~]# firewall-cmd --list-all --zone=external
#網關服務器如何關閉僞裝
重載防火牆則會重新啓動僞裝,external默認開啓僞裝
4)在命令行啓動僞裝 192.168.1.0/24
[root@gatway ~]# firewall-cmd --zone=external --add-rich-rule='rule family=ipv4 source address=192.168.1.0/24 masquerade'
[root@gatway ~]# firewall-cmd --reload
5)在企業內部網站上訪問internet網站服務器100.1.1.20
不能訪問。說明已經僞裝生效
4、外網web服務器訪問企業內部網站服務器
1)在網關服務器上配置端口轉發,實現外網web服務器能訪問企業內部網站服務器
[root@gatway ~]# firewall-cmd --zone=external --add-forward-port=port=443:proto=tcp:toaddr=192.168.2.10 --permanent
[root@gatway ~]# firewall-cmd --reload
2)在internet外部服務器上訪問測試,可以訪問到內部網站服務器
三、總結
凡是涉及到修改配置或者修改規則,一定要重啓或重載服務
此次實驗遇到問題:
一、企業內網無法訪問網站服務器
解決方法:
1、檢查各個IP地址是否衝突
2、檢查網關是否正常(企業內網網關與內網站網均分別指向網關服務器對應的接口)
3、檢查網關服務器的路由轉發功能是否生效
二、ssh登錄測試失敗
1、檢查端口是否正確
2、檢查sshd服務是否有啓動 netstat -natp | grep 12345
問題總結
A服務器連接B服務器,連接某個功能模塊連接不上?
解決方案
-
檢查B服務器的,功能模塊服務有沒有啓動
檢查環境–根據業務環境來
檢查配置文件–肉眼不一定看出來、建議使用比對工具比對配置文件
重啓服務服務–服務不要忘了重啓,不重要的服務就重啓,重要的的服務,重載下
本地驗證服務–ssh -p 端口號ip地址(環回口、接口的IP)
-
檢查B服務器的防火牆
檢查接口配置信息–看功能服務是否正常(多了就刪除,少了就添加)
-
檢查A服務器的防火牆
檢查接口配置信息–看功能服務是否正常(防火牆關閉)
windows檢測端口是否啓動:telnet IP地址 端口