Skip to content

Commit 0dec917

Browse files
committed
tf/setup: Persist iptables gw rules
Otherwise gateway functionality is broken after a reboot. Signed-off-by: Manuel Mendez <[email protected]>
1 parent 8d9d65a commit 0dec917

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

deploy/terraform/setup.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ install_docker_compose() {
1212
pip install docker-compose
1313
}
1414

15+
install_iptables_persistent() {
16+
apt-get install --no-install-recommends iptables-persistent
17+
}
18+
1519
apt-get() {
1620
DEBIAN_FRONTEND=noninteractive command apt-get \
1721
--allow-change-held-packages \
@@ -88,16 +92,27 @@ setup_layer2_network() {
8892

8993
# make_host_gw_server makes the host a gateway server
9094
make_host_gw_server() {
91-
local incoming_interface="$1"
92-
local outgoing_interface="$2"
95+
local incoming_interface=$1
96+
local outgoing_interface=$2
97+
98+
# drop all rules, especially interested in droppin docker's we don't want to persist docker's rules
99+
# docker will re-create them when starting back up
100+
systemctl stop docker
101+
netfilter-persistent flush
102+
93103
iptables -t nat -A POSTROUTING -o "${outgoing_interface}" -j MASQUERADE
94104
iptables -A FORWARD -i "${outgoing_interface}" -o "${incoming_interface}" -m state --state RELATED,ESTABLISHED -j ACCEPT
95105
iptables -A FORWARD -i "${incoming_interface}" -o "${outgoing_interface}" -j ACCEPT
106+
107+
netfilter-persistent save
108+
systemctl start docker
96109
}
97110

98111
main() {
112+
update_apt
99113
install_docker
100114
install_docker_compose
115+
install_iptables_persistent
101116

102117
local layer2_ip=192.168.56.4
103118
local layer2_interface

0 commit comments

Comments
 (0)