0593a6b372
* added docker-hosts for simplified hosts listing
29 lines
820 B
Bash
Executable File
29 lines
820 B
Bash
Executable File
#!/bin/bash
|
|
## docker-iptables
|
|
##
|
|
## @author gdm85
|
|
## script to show iptables rules with docker names
|
|
## can be used also to detect problems with dead containers and stale iptable rules
|
|
## supports standard iptables-save syntax
|
|
#
|
|
|
|
function replace_iptables() {
|
|
local CID
|
|
|
|
local SEDCMD="-e s!172.17.42.1/32!dockerHost!g
|
|
for CID in $(docker ps -q -a); do
|
|
local NAME=$(docker inspect --format '{{ .Name }}' $CID | awk '{ print substr($0, 2, length($0)-1) }')
|
|
local IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CID)
|
|
|
|
if [ -z "$IP" ]; then
|
|
continue
|
|
fi
|
|
|
|
SEDCMD="$SEDCMD -e s!$IP/32!${NAME}!g -e s!$IP!${NAME}!g"
|
|
done
|
|
|
|
sed $SEDCMD
|
|
}
|
|
|
|
iptables-save $@ | replace_iptables
|