Linux防火墙安装与配置
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Linux防火墻安裝與配置流程
一、iptables構建防火墻應用
? ? ? ? 步驟如下? ? ? ?
? ? ? ?1、service iptables status? ? ? ? ? ? 檢查是否安裝了iptables? ? ? ?
? ? ? ?2、systemctl stop firewalld? ? ? ? ? 關閉Linux默認防火墻firewalld?
? ? ? ?3、systemctl mask firewalld? ? ? ? ?禁用firewalld服務
? ? ? ?4、yum -y install iptables? ? ? ? ? ? ?安裝iptables
? ? ? ?5、yum update iptables? ? ? ? ? ? ? ?升級iptables
? ? ? ?6、yum install iptables-services? ?安裝服務
? ? ? ?7、systemctl status iptables? ? ? ? ?檢查安裝是否完成
? ? ? ?8、iptables -F -n? ? ? ? ? ? ? ? ? ? ? ? ? ?查看規則并開始配置
? ? ? ?----iptables常用規則
? ? ? ? ? ? ----iptables -L -n? ? ? ? 查看當前iptables規則
? ? ? ? ? ? -----? ?-F? 清除所有規則? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -p? 添加協議? ?后接協議名稱? 如TCP、UDP
? ? ? ? ? ? ----? ? -X? 清除所有自定義規則? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-s? 添加IP地址? ?后接IP地址
? ? ? ? ? ? ----? ? -Z? 所有計數器歸0? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? --dport? 端口? ? 后接端口號
? ? ? ? ? ? ----? ??-A? 添加規則? ?后接鏈名,如INPUT,OUTPUT,FORWARD? ? ???-j? 添加操作? ? ?后接操作指令 如ACCEPT、DROP
? ? ? ? ? ? ----? ? -D? 刪除規則? 后接鏈名,如INPUT,OUTPUT,FORWARD? ? ? ? -d? 目標地址? ?后接目標地址
? ? ? ? ? ? ----? ? -i? 指定網卡名,表示報文流入的接口? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-o 指定網卡名,表示報文流出的接口
? ? ? ? ? ? ----? ? -t? 指定表名 默認是filter
? ? ? 當命令配置完成以后,通過service iptables save 指令保存服務
? ? ? 配置完成以后需要重啟iptables,systemctl enable iptables.service? 注冊iptables服務;systemctl start iptables.service? ?開啟服務;
? ? ? systemctl status iptables.service? 查看狀態;systemctl restart iptables.service? 重啟防火墻
練習:外網IP 220.217.143.73,服務器A IP地址 10.0.0.1,服務器B IP地址? 10.0.0.2,無外網IP的服務器B想要通過有外網IP的服務器A去訪問外網,如何實現。
? ? ? ? ?首先,給服務器B配置其網關地址為服務器A的IP地址
? ? ? ? ? ? ? ? ? ?route add default gw 10.0.0.1
? ? ? ? ?其次,給服務器A啟用路由功能并配置iptables規則
? ? ? ? ? ? ? ? ? ?sysctl -w net.ipv4.ip_forward=1? ?啟用路由功能
? ? ? ? ? ? ? ? ? ?iptables -t filter -A FORWARD -j ACCEPT? ?打開轉發功能
? ? ? ? ? ? ? ? ? ?iptables -t nat -A POSTROUTING -o eth0 -j SANT -to 220.217.143.73? ?
? ? ? ? ?最后,讓三者實現數據流通
? ? ? ? ? ? ? ? ? ?iptables -t nat -A PREROUTING -d 220.217.143.73 -p tcp --dport 3306 -j DNAT --to-destination 10.0.0.2
? ? ? ? ? ? ? ? ? ?iptables -t nat -A POSTROUTING -d 10.0.0.2 -p tcp -m tcp --dport 3306 -j SNAT --to-source?10.0.0.1
二、TCP Wrappers 構建應用訪問控制列表
? ? ? ? ? vi /etc/hosts.aoolw 進行編輯
? ? ? ? ? 格式為? ?服務名:IP:allow(允許)/deny(禁止)
三、安裝DenyHosts防止暴力破解
? ? ? ? 1、?wget 'https//sourceforge.net/projects/denyhosts/files/denyhosts/2.6/DenyHosts-2.6.tar.gz/download' -O DenyHosts-2.6.tar.gz
? ? ? ? 2、tar zxvf DenyHosts-2.6.tar.gz? ? ?解壓壓縮包
? ? ? ? 3、cd DenyHosts-2.6? ? ?進入解壓后的文件?
? ? ? ? 4、python setup.py install? ? 進行安裝
? ? ? ? 5、cp daemon-control-dist daemon-control
? ? ? ? ? ? ? cp denyhosts.cfg-dist denyhosts.cfg? ? ? ? ? ?將這兩個文件復制為配置文件
? ? ? ? 6、ln daemon-control /etc/init.d? ?創建連接
? ? ? ? ? ? ?/etc/init.d/daemon-control start? ?啟動
?
? ? ??
總結
以上是生活随笔為你收集整理的Linux防火墙安装与配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机人工智能学院院徽,关于公布信息工程
- 下一篇: 比 top 更好,Linux 下的 7