淇濊瘉Linux绯荤粺瀹夊叏涔嬮厤缃甪irewalld闃茬伀澧欑殑鍦板潃浼鍙婄鍙h浆鍙戝疄渚嬶紝鍙窡鍋氾紒锛侊紒

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了淇濊瘉Linux绯荤粺瀹夊叏涔嬮厤缃甪irewalld闃茬伀澧欑殑鍦板潃浼鍙婄鍙h浆鍙戝疄渚嬶紝鍙窡鍋氾紒锛侊紒相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e8%a7%84%e5%88%99' title='瑙勫垯'>瑙勫垯   閰嶇疆淇℃伅   缃戠珯鏈嶅姟   鐢ㄦ埛   鍏綉ip鍦板潃   鍏抽棴   erro   auth   protocol   

鍏充簬闃茬伀澧欏熀纭€閰嶇疆鍙弬鑰冨崥鏂囷細淇濊瘉Linux绯荤粺瀹夊叏涔婥entOS 7 firewalld闃茬伀澧欏叆闂ㄨ瑙?/a>

妗堜緥鐜锛?/h3>

鎶€鏈浘鐗? src=

闇€姹傛弿杩帮細

  • 杩炴帴鍐呯綉缃戝崱ens33鍦板潃涓?92.168.1.1锛屽垎閰嶅埌firewall鐨則rusted鍖哄煙锛?br/>杩炴帴鏈嶅姟鍣ㄧ綉鍗ns37鍦板潃涓?92.168.2.1锛屽垎閰嶅埌firewall鐨刣mz鍖哄煙锛?br/>缃戝叧鏈嶅姟鍣ㄨ繛鎺ヤ簰鑱旂綉缃戝崱ens38鍦板潃涓?92.168.3.1锛屼负鍏綉IP鍦板潃锛屽垎閰嶅埌firewall鐨別xternal鍖哄煙锛?/li>
  • 缃戠珯鏈嶅姟鍣ㄥ拰缃戝叧鏈嶅姟鍣ㄥ潎閫氳繃SSH鏉ヨ繙绋嬬鐞嗭紝涓轰簡瀹夊叏锛屽皢SSH榛樿绔彛鏀逛负12345锛?/li>
  • 缃戠珯鏈嶅姟鍣ㄥ紑鍚? HTTPS锛岃繃婊ゆ湭鍔犲瘑鐨凥TTP娴侀噺锛?/li>
  • 缃戠珯鍔″櫒鎷掔粷ping娴嬭瘯,缃戝叧鏈嶅姟鍣ㄦ嫆缁濇潵鑷簰鑱旂綉涓婄殑ping娴嬭瘯锛?/li>
  • 鍏徃鍐呯綉鐢ㄦ埛闇€瑕侀€氳繃缃戝叧鏈嶅姟鍣ㄥ叡浜笂缃戯紱
  • 浜掕仈缃戠敤鎴烽渶瑕佽闂綉绔欐湇鍔″櫒锛?/li>

鎿嶄綔姝ラ

  • 鍩烘湰鐜閰嶇疆锛?/li>
  • DMZ缃戠珯鏈嶅姟鍣ㄧ幆澧冩惌寤哄苟鍚姩鏈嶅姟锛?/li>
  • DMZ缃戠珯鏈嶅姟鍣ㄤ笂鍚姩骞堕厤缃甪irewalld闃茬伀澧欑瓥鐣ワ紱
  • Internet娴嬭瘯缃戠珯鐜鎼缓骞跺惎鍔ㄦ湇鍔°€佽缃槻鐏瑙勫垯锛?/li>
  • 缃戝叧鏈嶅姟鍣ㄩ厤缃甪irewalld绛栫暐锛?/li>
  • 閰嶇疆IP浼涓庣鍙h浆鍙戯紱

妗堜緥瀹炴柦

1.鍩烘湰鐜閰嶇疆

锛?锛夌‘璁ょ綉鍏虫湇鍔″櫒鍦板潃
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.1  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::46cb:a832:aea4:7b65  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:00:11:89  txqueuelen 1000  (Ethernet)
        RX packets 158  bytes 46815 (45.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 31  bytes 4270 (4.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.1  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::8e69:6ed5:da33:fda4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:00:11:93  txqueuelen 1000  (Ethernet)
        RX packets 104  bytes 27490 (26.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 189  bytes 31923 (31.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost ~]# ifconfig ens38
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.1  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::5348:53e2:b3bc:d35b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:00:11:9d  txqueuelen 1000  (Ethernet)
        RX packets 101  bytes 27238 (26.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 188  bytes 31304 (30.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
锛?锛夌綉鍏虫湇鍔″櫒寮€鍚矾鐢卞姛鑳?/h5>
[root@localhost ~]# vim /etc/sysctl.conf
                 鈥︹€︹€︹€︹€︹€?              //鐪佺暐閮ㄥ垎鍐呭锛屾坊鍔犱互涓嬪唴瀹?net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
锛?锛夐厤缃瓺MZ鍖哄煙缃戠珯鏈嶅姟鍣ㄥ湴鍧€銆佺綉鍏?/h5>
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.2  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::8744:c79c:521f:823f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2b:56:b5  txqueuelen 1000  (Ethernet)
        RX packets 114  bytes 34398 (33.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 4162 (4.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    100    0        0 ens33
锛?锛夐厤缃甀nternet娴嬭瘯缃戠珯鏈嶅姟鍣↖P鍦板潃銆佺綉鍏?/h5>
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.2  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::7c8b:1ec0:7e4d:ac6  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:98:41:ac  txqueuelen 1000  (Ethernet)
        RX packets 113  bytes 31388 (30.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 4541 (4.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.3.1     0.0.0.0         UG    100    0        0 ens33
锛?锛夐厤缃唴閮ㄥ鎴锋満IP鍦板潃銆佺綉鍏?/h5>
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::9bb5:2c48:1095:d75a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:fb:76:60  txqueuelen 1000  (Ethernet)
        RX packets 106  bytes 29223 (28.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 31  bytes 4349 (4.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 ens33

2.DMZ缃戠珯鏈嶅姟鍣ㄧ幆澧冨苟鍚姩鏈嶅姟

锛?锛夊紑鍚痜irewalld闃茬伀澧?/h5>
[root@localhost ~]# systemctl start firewalld
锛?锛夋惌寤篽ttpd鏈嶅姟
[root@localhost ~]# yum -y install httpd
//鍩轰簬http璁块棶鐨凥TTP缃戠珯
[root@localhost ~]# yum -y install httpd mod_ssl
//鍩轰簬https璁块棶鐨凥TTP缃戠珯
[root@localhost ~]# systemctl start httpd
//寮€鍚疕TTP鏈嶅姟
锛?锛夋洿鏀筍SH鐨勭洃鍚鍙o紙閲嶅惎鏈嶅姟鏃跺缓璁叧闂璖ELinux锛?/h5>
[root@localhost ~]# vim /etc/ssh/sshd_config 
                   鈥︹€︹€︹€?      //鐪佺暐閮ㄥ垎鍐呭锛屼慨鏀逛互涓嬪唴瀹?Port 12345
[root@localhost ~]# setenforce 0
//涓存椂鍏抽棴SELinux
[root@localhost ~]# systemctl restart sshd
//閲嶅惎ssh鏈嶅姟

3.DMZ缃戠珯鏈嶅姟鍣ㄤ笂鍚姩骞堕厤缃甪irewalld闃茬伀澧欑瓥鐣?/h4>

锛?锛夎缃槻鐏榛樿鍖哄煙涓篸mz鍖哄煙
[root@localhost ~]# firewall-cmd --set-default-zone=dmz
success
锛?锛変负dmz鍖哄煙娣诲姞鐩稿簲鏈嶅姟鍙婄鍙?/h5>
[root@localhost ~]# firewall-cmd --zone=dmz --add-service=https
success
[root@localhost ~]# firewall-cmd --zone=dmz --add-port=12345/tcp
success
锛?锛夌姝ing娴嬭瘯
[root@localhost ~]# firewall-cmd --zone=dmz --add-icmp-block=echo-request
success
锛?锛夊皢榛樿鐨剆sh鏈嶅姟鍒犻櫎
[root@localhost ~]# firewall-cmd --zone=dmz --remove-service=ssh
success
锛?锛変繚瀛樺綋鍓嶉槻鐏閰嶇疆
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
//灏嗕复鏃堕厤缃浆鎹负姘镐箙閰嶇疆
[root@localhost ~]# firewall-cmd --list-all --zone=dmz
//鏌ョ湅骞剁‘璁ら厤缃俊鎭?dmz (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: https
  ports: 12345/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  sourceports: 
  icmp-blocks: echo-request
  rich rules: 

4. Internet娴嬭瘯缃戠珯鐜鎼缓骞跺惎鍔ㄦ湇鍔°€佽缃槻鐏瑙勫垯

鎼缓鏂规硶鍙弬鑰冪2銆?姝?/p>

5. 缃戝叧鏈嶅姟鍣ㄩ厤缃甪irewalld绛栫暐

锛?锛夊紑鍚槻鐏
[root@localhost ~]# systemctl start firewalld
锛?锛夎缃粯璁ゅ尯鍩熶负externel鍖哄煙
[root@localhost ~]# firewall-cmd --set-default-zone=external
success
锛?锛夊皢鍚勪釜缃戝崱鍒嗛厤鑷虫寚瀹氬尯鍩?/h5>
[root@localhost ~]# firewall-cmd --change-interface=ens33 --zone=trusted
success
[root@localhost ~]# firewall-cmd --change-interface=ens37 --zone=dmz
success
锛?锛夊唴閮ㄥ鎴锋満璁块棶DMZ缃戠珯娴嬭瘯
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
[root@localhost ~]# firewall-cmd --get-active-zones
dmz
  interfaces: ens37
external
  interfaces: ens38
trusted
  interfaces: ens33
锛?锛夊唴閮ㄥ鎴锋満璁块棶缃戠珯鏈嶅姟鍣?/h5>

鎶€鏈浘鐗? src=
鎶€鏈浘鐗? src=

锛?锛夋洿鏀箂sh鏈嶅姟鐩戝惉绔彛
[root@localhost ~]# vim /etc/ssh/sshd_config 
                   鈥︹€︹€︹€?      //鐪佺暐閮ㄥ垎鍐呭锛屼慨鏀逛互涓嬪唴瀹?Port 12345
[root@localhost ~]# setenforce 0
//涓存椂鍏抽棴SELinux
[root@localhost ~]# systemctl restart sshd
//閲嶅惎ssh鏈嶅姟
锛?锛夐厤缃甧xternal鍖哄煙娣诲姞TCP鐨?2345绔彛銆佺Щ闄sh鏈嶅姟
[root@localhost ~]# firewall-cmd --zone=external --add-port=12345/tcp
success
[root@localhost ~]# firewall-cmd --zone=external --remove-service=ssh
success
锛?锛夐厤缃甧xternal鍖哄煙杩涜ping娴嬭瘯銆佷繚瀛樹负姘镐箙閰嶇疆
[root@localhost ~]# firewall-cmd --zone=external --add-icmp-block=echo-request
success
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
锛?锛塈nternet娴嬭瘯鏈嶅姟鍣ㄨ繙绋嬬綉鍏虫湇鍔″櫒
[root@localhost ~]# ssh -p 12345 192.168.3.1
The authenticity of host 鈥榌192.168.3.1]:12345 ([192.168.3.1]:12345)鈥?can鈥榯 be established.
ECDSA key fingerprint is b2:4e:e8:f9:23:9f:85:dc:54:87:97:eb:15:cc:b0:48.
Are you sure you want to continue connecting (yes/no)? 
锛?0锛夊唴閮ㄥ鎴锋満杩滅▼DMZ缃戠珯鏈嶅姟鍣?/h5>
[root@localhost ~]# ssh -p 12345 192.168.2.2
The authenticity of host 鈥榌192.168.2.2]:12345 ([192.168.2.2]:12345)鈥?can鈥榯 be established.
ECDSA key fingerprint is 25:54:5c:d5:ce:e1:04:9f:25:19:be:73:ce:93:86:54.
Are you sure you want to continue connecting (yes/no)? 

6.缃戝叧鏈嶅姟鍣ㄤ笂閰嶇疆IP杞彂涓庣鍙h浆鍙?/h4>

榛樿external鍖哄煙鏈塈P杞彂鍔熻兘锛?/strong>

锛?锛夊垹闄xternal鍖哄煙涓殑IP浼锛屽苟鍒╃敤瀵岃鍒欏紑鍚?/h5>
[root@localhost ~]# firewall-cmd --remove-masquerade --zone=external
success
[root@localhost ~]# firewall-cmd --zone=external --add-rich-rule=鈥榬ule family=ipv4 source address=192.168.1.0/24 masquerade鈥?success
锛?锛塪mz缃戠珯鏈嶅姟鍣ㄦ祴璇曡闂甀nternet娴嬭瘯缃戠珯

鎶€鏈浘鐗? src=

锛?锛夐厤缃鍙h浆鍙戝疄鐜癐nternet娴嬭瘯缃戠珯璁块棶dmz鍖哄煙缃戠珯鏈嶅姟鍣紙鐩存帴瑙勫垯锛?/h5>
[root@localhost ~]# firewall-cmd --zone=external --add-forward-port=port=443:proto=tcp:toaddr=192.168.2.2
success
//缃戝叧鏈嶅姟鍣ㄥ皢浜掕仈缃戞祴璇曟満鐨勮姹傝浆鍙戝埌dmz鍖哄煙缃戠珯鏈嶅姟鍣?/code>
锛?锛夋祴璇?/h5>

鎶€鏈浘鐗? src=

锛?锛夐厤缃鍙h浆鍙戝疄鐜癐nternet娴嬭瘯缃戠珯璁块棶dmz鍖哄煙缃戠珯鏈嶅姟鍣紙瀵岃鍒欙級

闇€鍦╡ns38缃戝崱涓婇厤缃竴涓复鏃禝P鍦板潃

[root@localhost ~]# firewall-cmd --zone=external --add-rich-rule=鈥榬ule family=ipv4 destination address=192.168.3.100 forward-port port=443 protocol=tcp to-addr=192.168.2.2鈥?success
锛?锛夋祴璇?/h5>

鎶€鏈浘鐗? src=

以上是关于淇濊瘉Linux绯荤粺瀹夊叏涔嬮厤缃甪irewalld闃茬伀澧欑殑鍦板潃浼鍙婄鍙h浆鍙戝疄渚嬶紝鍙窡鍋氾紒锛侊紒的主要内容,如果未能解决你的问题,请参考以下文章

IIS7.0 Windows Server 2008 R2 涓嬮厤缃瘉涔︽湇鍔″櫒鍜孒TTPS鏂瑰紡璁块棶缃戠珯

瀹夊崜鎵嬫満鐢ㄤ笂iPhone绯荤粺锛佺偒閰凤紒

centos7绯荤粺涓嬪畨瑁卲hp-fpm骞堕厤缃畁ginx鏀寔骞跺紑鍚綉绔檊zip鍘嬬缉

榛戣嫻鏋滃紑鑽掕绯荤粺绡? 瓒呰缁嗙殑绾噣 MacOS 瀹夎娴佺▼

濡備綍鍦ㄥ懡浠よ涓嬫鏌ョ‖鐩橈紵

(c)2006-2024 SYSTEM All Rights Reserved IT常识