You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
796 B
Plaintext
29 lines
796 B
Plaintext
10 years ago
|
#!/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() {
|
||
9 years ago
|
local CID
|
||
10 years ago
|
|
||
9 years ago
|
local SEDCMD=""
|
||
|
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)
|
||
10 years ago
|
|
||
9 years ago
|
if [ -z "$IP" ]; then
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
SEDCMD="$SEDCMD -e s!$IP/32!${NAME}!g -e s!$IP!${NAME}!g"
|
||
|
done
|
||
|
|
||
|
sed $SEDCMD
|
||
10 years ago
|
}
|
||
|
|
||
|
iptables-save $@ | replace_iptables
|