linux 各系统防火墙操作
Centos7
查看:sudo systemctl status firewalld
臨關(guān):sudo systemctl stop firewalld
臨開(kāi):sudo systemctl start firewalld
永關(guān):sudo systemctl disable firewalld
查詢防火墻服務(wù)是否開(kāi)機(jī)啟動(dòng):systemctl is-enabled firewalld
查詢已經(jīng)啟動(dòng)的服務(wù)列表:systemctl list-unit-files|grep enabled
添加端口:firewall-cmd?--zone=public?--add-port=80/tcp?--permanent?
更新防火墻規(guī)則:firewall-cmd?--reload
查看端口狀態(tài):firewall-cmd?--zone=public?--query-port=80/tcp
刪除開(kāi)放的端口:firewall-cmd?--zone=public?--remove-port=80/tcp?--permanent
每次都更新防火墻規(guī)則,都需要重新更新:firewall-cmd?--reload,更新?tīng)顟B(tài);
此外,在更新完防火墻的設(shè)置后,也可以查看所有開(kāi)啟的端口:firewall-cmd --zone=public --list-ports
?
Centos 6
1) 重啟后生效?
開(kāi)啟: chkconfig iptables on?
關(guān)閉: chkconfig iptables off?
?
2) 即時(shí)生效,重啟后失效?
開(kāi)啟: service iptables start?
關(guān)閉: service iptables stop?
?
?
Ubuntu
查看:sudo ufw status ?inactive狀態(tài)是防火墻關(guān)閉狀態(tài) active是開(kāi)啟狀態(tài)。
開(kāi)啟:sudo ufw enable
關(guān)閉:sudo ufw disable
fw default allow/deny:外來(lái)訪問(wèn)默認(rèn)允許/拒絕
ufw allow/deny 20:允許/拒絕 訪問(wèn)20端口,20后可跟/tcp或/udp,表示tcp或udp封包。
ufw allow/deny servicename:ufw從/etc/services中找到對(duì)應(yīng)service的端口,進(jìn)行過(guò)濾。
ufw allow proto tcp from 10.0.1.0/10 to 本機(jī)ip port 25:允許自10.0.1.0/10的tcp封包訪問(wèn)本機(jī)的25端口。
ufw delete allow/deny 20:刪除以前定義的"允許/拒絕訪問(wèn)20端口"的規(guī)則
開(kāi)放端口:iptables -I INPUT -p tcp --dport 9222 -j ACCEPT
查看規(guī)則:iptables -t nat -nL --line? 或?iptables -t nat -vnL PREROUTING --line-number
刪除規(guī)則:刪除指定表的指定鏈上的規(guī)則, -D 并指定序號(hào)即可:iptables -t nat -D PREROUTING 1
中間人要把流量轉(zhuǎn)發(fā)到真實(shí)地址,就要開(kāi)啟路由功能
- sysctl -w net.ipv4.ip_forward=1
- 其實(shí)就是修改了文件的值:cat /proc/sys/net/ipv4/ip_forward
端口轉(zhuǎn)發(fā):iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 #HTTPS(80端口(既服務(wù)原始端口)流量重定向8080)
清空規(guī)則:iptables -t nat -F(清空復(fù)原)
總結(jié)
以上是生活随笔為你收集整理的linux 各系统防火墙操作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 33. 脱壳篇-重建输入表
- 下一篇: linux 其他常用命令