搭建防火墙服务
搭建網絡防火墻
? ? 防火墻的IP充當網關,對兩邊主機相互發送的數據包進行檢查
1 兩邊的主機都必須要配置 2 主機1配置路由: 3 route add -net 192.168.145.0/24 gw 192.168.33.129 4 route del -net 192.168.33.0/24 5 inet 192.168.33.128 6 7 路由主機的IP當成網關 8 eth0 inet addr:192.168.33.130 9 eth1 inet addr:192.168.145.130 10 11 主機2配置路由: 12 route add -net 192.168.33.0/24 gw 192.168.145.130 13 inet 192.168.145.128 14 跨網段ping主機: 15 ping 192.168.33.128 16 PING 192.168.33.128 (192.168.33.128) 56(84) bytes of data. 17 64 bytes from 192.168.33.128: icmp_seq=1 ttl=63 time=0.920 ms 18 64 bytes from 192.168.33.128: icmp_seq=2 ttl=63 time=2.41 ms 19 64 bytes from 192.168.33.128: icmp_seq=3 ttl=63 time=2.26 ms 20 21 [root@centos7 network-scripts]# ping 192.168.145.128 22 PING 192.168.145.128 (192.168.145.128) 56(84) bytes of data. 23 如果一直停住在這里表示對方接收到了數據包,但是沒有路由返回. 24 25 vi /etc/hosts 26 192.168.33.128 www.a.com www.b.com www.c.com 27 curl www.a.com 28 29 在路由主機上配置路由規則 30 2.iptables -I FORWARD -m string --algo bm --string "a.com" -j REJECT 31 32 iptables -A FORWARD -j REJECT 33 #拒絕所有的轉發包 34 iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT 35 #允許轉發外部主機的響應包 36 iptables -I FORWARD 2 -s 192.168.145.0/24 -m state --state NEW -j ACCEPT 37 #允許內部主機主動發起請求訪問外部主機 38 [root@yxh6 ~]# iptables -I FORWARD 2 -d 192.168.145.128 -p tcp --dport 22 -m state --state NEW -jACCEPT 39 #允許外部主機訪問內網的特定主機的特定服務 View Code?
防火墻實現NAT(網絡地址轉換)
? ?SNAT
? ? ? ?修改了請求報文中的源IP? ? ?不修改端口? ? ? ? 實現企業內網中的所有主機公用一個公網IP連接互聯網
? ? ? ?iptables? ? -t? ?nat? ? ?-A? ? POSTROUTING? ? -s? ?10.0.1.0/24? ? -j? ?SNAT? ? -to-source 172.18.1.6
? ? ? ?iptables? ? -t? ? nat? ? -A? ? POSTROUTING? ? -s? ?10.0.1.0/24? ? -j? ?MASQUERADE
?
?DNAT
? ? ? 修改了請求報文中的目標IP? ?不修改端口? ? ? ? 實現公網中的主機通過內網網關IP訪問到內部企業內網的主機
? ? ???iptables? ? -t? ?nat? ? -A? ? PREROUTING? ? -s? ? 0/0? ? -d? ? 172.18.100.6? ?-p? ? tcp? ? --dport? 80? ?-j? ? ? DNAT? ? --todestination 10.0.1.22:8080?
? ?
端口轉發?
? ? ?iptables? ? -t? ? nat? ? -A? ? ? PREROUTING? ? -d? ? ?172.16.100.10? ? -p? ? tcp? ? --dport 80? ?-j? ? REDIRECT? ? --to-ports? 8080
? ??
管理防火墻中的表規則? ??
? ? ? 查看防火墻指定表中的規則記錄? ? ?默認管理的是filter表? 如果要管理其它的表,需要添加 -t 選項
? ? ? [root@yxh6 ~]# iptables -nvL -t nat? ? ? ? ? ? 列出nat表里面的所有記錄
? ? ? [root@yxh6 ~]# iptables -F -t nat? ? ? ? ? ? ? ? 刪除nat表里面的所有記錄
?
firewalld服務?
? ? ?firewalld是CentOS 7.0新推出的管理netfilter的工具
? ? ?firewalld是配置和監控防火墻規則的系統守護進程.可以實現 iptables,ip6tables,ebtables的功能?
? ? ?firewalld服務由firewalld包提供?
? ? ?firewalld支持劃分區域zone,每個zone可以設置獨立的防火墻規則?
? ? ?網卡默認屬于public zone,lo網絡接口屬于trusted? zone?
? ? ?firewalld配置?
? ? ? ? 1.? ? ?firewall-config (firewall-config包)圖形工具?
? ? ? ? 2.? ? ??firewall-cmd (firewalld包)命令行工具?
? ??
轉載于:https://www.cnblogs.com/yxh168/p/9248246.html
總結
- 上一篇: 岩土工程物探测试检测监测资质代办需要多久
- 下一篇: 车灯升级精刚品牌怎么样呢效果好吗有没有安