DEV Community


Posted on

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 ${["subnet"]}",
      "sudo firewall-cmd --reload",
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

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 "". I also included dnsmasq with a very basic config.