
我正在編寫一個腳本來透過命令列查找所有防火牆詳細資訊、路由資訊和重要的網路相關資訊。我可以使用 取得防火牆配置iptables -nvL
,但我不確定其餘的。我應該使用什麼命令來收集其他所有內容?
答案1
您可以透過以下方式取得介面狀態:
ifconfig
或者更好的是,使用“ip”命令,例如:
ip addr
要獲取路線信息,請使用以下方法之一:
route
route -n #no ptr resolving
ip route
對於防火牆規則,請使用:
iptables -L # you can add -n to prevent name resolving
對於 IPv6,您可以將“-6”新增至“ip”命令:
ip -6 addr
ip -6 route
...
您還可以檢查“ethtool”以獲取連結狀態和速度/雙工:
ethtool eth0
答案2
routel
列出了大量信息,儘管以不真正可讀的形式,但它是主機所有路由表的完整轉儲,並提供了足夠的信息來重建主機上的 IP 配置。此資訊不夠完整,無法重建策略路由。如果你碰巧使用它,你還需要ip rule
.無論如何,以 IPv4 為例(即使也列出了 IPv6):
# list all interfaces addresses (unicast/broadcast/anycast)
routel | grep "local"
# list all (except ipv6 link-local) addresses of interfaces
routel | grep "local" | grep "host"
# list all broadcast addresses of interfaces
routel | grep "local" | grep "link"
# list all routing entries
routel | grep -v "local" | grep -v "unspec"
# list all on-link routing entries
routel | grep -v "local" | grep -v "unspec" | grep "link"
# list all on-link routing entries that are added by the kernel,
# (which also matches the netmask of the IP addresses).
routel | grep -v "local" | grep -v "unspec" | grep "link" | grep "kernel"
# list non-on-link routes (aka gatewayed or routed)
routel | grep -v "local" | grep -v "unspec" | grep -v "link"
ip route
與1999 的相反route
,routel 列出所有路由表,而 other 只列出main
表。如果有人使用策略路由,那麼使用時你將不會得到任何線索ip route
,而routel會為你拼出路由表的名稱。
另外,您可能想要轉儲 sysctl 旋鈕,以了解是否有人啟用了轉發、ARP 代理或其他一些時髦的東西。只是轉儲sysctl -a
如果您想要更完整的標誌或介面訊息,也可以 dump ip addr
。真正特殊的配置可能需要更多,例如ip link
或ip tunnel
。
至於防火牆配置,有iptables-save
或iptables-save -c
如果您還需要計數器。這將列出所有表(不僅filter
像 iptables -L 或 iptables -S),您甚至可以使用iptables-restore
它來獲取 iptables-save 的輸出並恢復其配置。
答案3
列印現有 iptables 規則的命令如下:
iptables-L
答案4
您可以查看是否安裝了 CSF 防火牆。
/etc/csf/csf.conf