netstat 可用於查看監聽端口、連線狀態與通訊對象。
netstat -lnp netstat -an netstat -an | grep 192.168.111.129:80 | grep -ic ESTAB
tcpdump 可抓取指定網卡、端口與主機的封包,也可將結果寫入檔案。
tcpdump -nn tcpdump -nn -c 100 tcpdump -nn -i eth1 tcpdump -nn port 22 tcpdump -nn -s0 tcp and port 22 and host 192.169.111.128 -w 1.cap tcpdump -r 1.cap
tshark 可針對 HTTP 請求等欄位進行擷取與分析。
tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
getenforce setenforce 0 setenforce 1
iptables 常使用 filter、nat、mangle 三張表。filter 主要做封包過濾,nat 用於位址轉換,mangle 可標記封包。
iptables -t filter -nvL iptables -t filter -I INPUT -p tcp --dport 80 -s 192.168.111.123 -j DROP iptables -P INPUT ACCEPT iptables -nvL iptables -t filter -D INPUT -p tcp --dport 80 -s 192.168.111.123 -j REJECT iptables -Z iptables -F service iptables save iptables-save > 1.ipt iptables-restore < 1.ipt
、-A 與 -I 的差異在於新增位置:-A 加在規則末端,-I 加在規則前端,而前端規則通常優先生效。