DEV Community

drewmullen
drewmullen

Posted on

3 1

Terraform: turn a centos vm into a linux router

while building your VM, enable IP forwarding and also pass this remote-exec

  provisioner "remote-exec" {
    inline = [
      "echo \"net.ipv4.ip_forward=1\" | sudo tee /etc/sysctl.d/ip_forward.conf",
      "sudo /usr/sbin/sysctl --system",
      "sudo systemctl start firewalld",
      "sudo systemctl enable firewalld",
      "sudo firewall-cmd --permanent --direct --passthrough ipv4 -I FORWARD -i eth0 -j ACCEPT",
      "sudo firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o eth0 -j MASQUERADE -s ${var.network["subnet"]}",
      "sudo firewall-cmd --reload",
    ]
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
flrichar profile image
Fred Richards

Love it! I have an old 2009-era HPMini laptop with Debian on it. I had a script which does pretty much the same thing called "imarouter.sh". I also included dnsmasq with a very basic config.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more