Terraform: turn a centos vm into a linux router

drewmullen profile image drewmullen ・1 min read

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",


markdown guide

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.