Copy Foreman deploy logic from bgs_vagrant repo
[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 if ! yum -y install iptables-services; then
22   printf '%s\n' 'nat_setup.sh: Unable to install iptables-services' >&2
23   exit 1
24 fi
25
26 ##start and enable iptables service
27 if ! systemctl start iptables; then
28   printf '%s\n' 'nat_setup.sh: Unable to start iptables-services' >&2
29   exit 1
30 fi
31
32 systemctl enable iptables
33
34 ##enable IP forwarding
35 echo 1 > /proc/sys/net/ipv4/ip_forward
36
37 ##Configure iptables
38 /sbin/iptables -t nat -I POSTROUTING -o enp0s10 -j MASQUERADE
39 /sbin/iptables -I FORWARD 1 -i enp0s10 -o enp0s8 -m state --state RELATED,ESTABLISHED -j ACCEPT
40 /sbin/iptables -I FORWARD 1 -i enp0s8 -o enp0s10 -j ACCEPT
41 /sbin/iptables -I INPUT 1 -j ACCEPT
42 /sbin/iptables -I OUTPUT 1 -j ACCEPT
43