mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 21:55:43 -05:00
Bonus: Generalize and reuse cmd_ssh() Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
45 lines
1,020 B
Python
45 lines
1,020 B
Python
import click
|
|
import subprocess
|
|
from logger import logging
|
|
from ssh import cmd_ssh
|
|
|
|
|
|
@click.command(name='forwarding')
|
|
def cmd_forwarding():
|
|
result = subprocess.run([
|
|
'sysctl',
|
|
'net.ipv4.ip_forward=1',
|
|
])
|
|
if result.returncode != 0:
|
|
logging.fatal(f'Failed to enable ipv4 forward via sysctl')
|
|
exit(1)
|
|
|
|
result = subprocess.run([
|
|
'iptables',
|
|
'-P',
|
|
'FORWARD',
|
|
'ACCEPT',
|
|
])
|
|
if result.returncode != 0:
|
|
logging.fatal(f'Failed set iptables rule')
|
|
exit(1)
|
|
|
|
result = subprocess.run([
|
|
'iptables',
|
|
'-A',
|
|
'POSTROUTING',
|
|
'-t',
|
|
'nat',
|
|
'-j',
|
|
'MASQUERADE',
|
|
'-s',
|
|
'172.16.42.0/24',
|
|
])
|
|
if result.returncode != 0:
|
|
logging.fatal(f'Failed set iptables rule')
|
|
exit(1)
|
|
|
|
result = cmd_ssh(cmd=['sudo route add default gw 172.16.42.2'])
|
|
if result.returncode != 0:
|
|
logging.fatal(f'Failed to add gateway over ssh')
|
|
exit(1)
|