349e416d609275b2487dd2475ba8bba0f3c6e64e
[genesis.git] / foreman / ci / nat_setup.sh
1 #!/usr/bin/env bash
2
3 #NAT setup script to setup NAT from Admin -> Public interface
4 #on a Vagrant VM
5 #Called by Vagrantfile in conjunction with deploy.sh
6 #author: Tim Rozet (trozet@redhat.com)
7 #
8 #Uses Vagrant and VirtualBox
9 #VagrantFile uses nat_setup.sh which sets up NAT
10 #
11
12 ##make sure firewalld is stopped and disabled
13 if ! systemctl stop firewalld; then
14   printf '%s\n' 'nat_setup.sh: Unable to stop firewalld' >&2
15   exit 1
16 fi
17
18 systemctl disable firewalld
19
20 # Install iptables
21 # Major version is pinned to force some consistency for Arno
22 if ! yum -y install iptables-services-1*; then
23   printf '%s\n' 'nat_setup.sh: Unable to install iptables-services' >&2
24   exit 1
25 fi
26
27 ##start and enable iptables service
28 if ! systemctl start iptables; then
29   printf '%s\n' 'nat_setup.sh: Unable to start iptables-services' >&2
30   exit 1
31 fi
32
33 systemctl enable iptables
34
35 ##enable IP forwarding
36 echo 1 > /proc/sys/net/ipv4/ip_forward
37
38 ##Configure iptables
39 /sbin/iptables -t nat -I POSTROUTING -o enp0s10 -j MASQUERADE
40 /sbin/iptables -I FORWARD 1 -i enp0s10 -o enp0s8 -m state --state RELATED,ESTABLISHED -j ACCEPT
41 /sbin/iptables -I FORWARD 1 -i enp0s8 -o enp0s10 -j ACCEPT
42 /sbin/iptables -I INPUT 1 -j ACCEPT
43 /sbin/iptables -I OUTPUT 1 -j ACCEPT
44