Route so that AWS instance appears on internal network and vice-versa












0















I have an AWS Lightsail instance




  • to which I'd like route all traffic from my network directed to a specific (i.e.: 192.168.1.225) IP address

  • and from which I'd like to route all traffic directed to 192.168.1.0/24 via my public IP


I've been trying via iptables NAT but this doesn't seem to work either way:



# on my router
iptables -t nat -A PREROUTING -d 192.168.1.225 -j DNAT --to-destination $AWS_ADDRESS
iptables -t nat -A POSTROUTING -s $AWS_ADDRESS -j SNAT --to-source 192.168.1.225


and



# on lightsail
iptables -t nat -A PREROUTING -d 192.168.1.144 -j DNAT --to-destination $PUBLIC_IP
iptables -t nat -A POSTROUTING -s $PUBLIC_IP -j SNAT --to-source 192.168.1.144


What am I doing wrong here?










share|improve this question



























    0















    I have an AWS Lightsail instance




    • to which I'd like route all traffic from my network directed to a specific (i.e.: 192.168.1.225) IP address

    • and from which I'd like to route all traffic directed to 192.168.1.0/24 via my public IP


    I've been trying via iptables NAT but this doesn't seem to work either way:



    # on my router
    iptables -t nat -A PREROUTING -d 192.168.1.225 -j DNAT --to-destination $AWS_ADDRESS
    iptables -t nat -A POSTROUTING -s $AWS_ADDRESS -j SNAT --to-source 192.168.1.225


    and



    # on lightsail
    iptables -t nat -A PREROUTING -d 192.168.1.144 -j DNAT --to-destination $PUBLIC_IP
    iptables -t nat -A POSTROUTING -s $PUBLIC_IP -j SNAT --to-source 192.168.1.144


    What am I doing wrong here?










    share|improve this question

























      0












      0








      0








      I have an AWS Lightsail instance




      • to which I'd like route all traffic from my network directed to a specific (i.e.: 192.168.1.225) IP address

      • and from which I'd like to route all traffic directed to 192.168.1.0/24 via my public IP


      I've been trying via iptables NAT but this doesn't seem to work either way:



      # on my router
      iptables -t nat -A PREROUTING -d 192.168.1.225 -j DNAT --to-destination $AWS_ADDRESS
      iptables -t nat -A POSTROUTING -s $AWS_ADDRESS -j SNAT --to-source 192.168.1.225


      and



      # on lightsail
      iptables -t nat -A PREROUTING -d 192.168.1.144 -j DNAT --to-destination $PUBLIC_IP
      iptables -t nat -A POSTROUTING -s $PUBLIC_IP -j SNAT --to-source 192.168.1.144


      What am I doing wrong here?










      share|improve this question














      I have an AWS Lightsail instance




      • to which I'd like route all traffic from my network directed to a specific (i.e.: 192.168.1.225) IP address

      • and from which I'd like to route all traffic directed to 192.168.1.0/24 via my public IP


      I've been trying via iptables NAT but this doesn't seem to work either way:



      # on my router
      iptables -t nat -A PREROUTING -d 192.168.1.225 -j DNAT --to-destination $AWS_ADDRESS
      iptables -t nat -A POSTROUTING -s $AWS_ADDRESS -j SNAT --to-source 192.168.1.225


      and



      # on lightsail
      iptables -t nat -A PREROUTING -d 192.168.1.144 -j DNAT --to-destination $PUBLIC_IP
      iptables -t nat -A POSTROUTING -s $PUBLIC_IP -j SNAT --to-source 192.168.1.144


      What am I doing wrong here?







      iptables amazon-web-services






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 10 at 16:17









      simonesimone

      1215




      1215






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Have you considered/tried using ssh with port forwarding? I think you can only expect to forward a few ports, but this seems like exactly what it would do for you.






          share|improve this answer































            0














            First problem: You are trying to use an address which is local to your subnet. Same-subnet traffic does not go through the router and is not affected by the router's firewall rules. When other computers in your LAN want to reach 192.168.1.225, they instead immediately send local ARP queries to learn its MAC address.



            This can be avoided by using a different subnet for the AWS host, or by configuring Proxy-ARP on the router, making it spoof the ARP responses for that address.



            Second problem: IP packets can only carry one destination, so DNAT loses information – the recipient (your local router) no longer knows what the original destination was supposed to be. (Only the same host which performed the translation has this information.) So the AWS host can DNAT a single destination to your local public address, but cannot DNAT a whole /24.



            To avoid this, you need to tunnel the packets – instead of translating them, encapsulate the original packet within a second IP header. (Also called a VPN.) There are many options for configuring a tunnel on Linux, from plain IPIP or GRE to IPsec to WireGuard or Tinc or OpenVPN.



            Most tunnel/VPN types are L3 (they carry IP packets inside), so you will still need to use a different subnet number from the regular LAN subnet, and have the router actually route between LAN interface and VPN/tunnel interface.



            Some tunnels support L2 mode (carry Ethernet frames inside), e.g. EoIP, gretap, OpenVPN --dev-type tap, ZeroTier. These L2 tunnel interfaces can be bridged with your LAN, allowing the same subnet to be used on both sides (with fully working ARP), which is what you originally asked for.






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404175%2froute-so-that-aws-instance-appears-on-internal-network-and-vice-versa%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Have you considered/tried using ssh with port forwarding? I think you can only expect to forward a few ports, but this seems like exactly what it would do for you.






              share|improve this answer




























                0














                Have you considered/tried using ssh with port forwarding? I think you can only expect to forward a few ports, but this seems like exactly what it would do for you.






                share|improve this answer


























                  0












                  0








                  0







                  Have you considered/tried using ssh with port forwarding? I think you can only expect to forward a few ports, but this seems like exactly what it would do for you.






                  share|improve this answer













                  Have you considered/tried using ssh with port forwarding? I think you can only expect to forward a few ports, but this seems like exactly what it would do for you.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 10 at 16:43









                  Toby EggittToby Eggitt

                  1074




                  1074

























                      0














                      First problem: You are trying to use an address which is local to your subnet. Same-subnet traffic does not go through the router and is not affected by the router's firewall rules. When other computers in your LAN want to reach 192.168.1.225, they instead immediately send local ARP queries to learn its MAC address.



                      This can be avoided by using a different subnet for the AWS host, or by configuring Proxy-ARP on the router, making it spoof the ARP responses for that address.



                      Second problem: IP packets can only carry one destination, so DNAT loses information – the recipient (your local router) no longer knows what the original destination was supposed to be. (Only the same host which performed the translation has this information.) So the AWS host can DNAT a single destination to your local public address, but cannot DNAT a whole /24.



                      To avoid this, you need to tunnel the packets – instead of translating them, encapsulate the original packet within a second IP header. (Also called a VPN.) There are many options for configuring a tunnel on Linux, from plain IPIP or GRE to IPsec to WireGuard or Tinc or OpenVPN.



                      Most tunnel/VPN types are L3 (they carry IP packets inside), so you will still need to use a different subnet number from the regular LAN subnet, and have the router actually route between LAN interface and VPN/tunnel interface.



                      Some tunnels support L2 mode (carry Ethernet frames inside), e.g. EoIP, gretap, OpenVPN --dev-type tap, ZeroTier. These L2 tunnel interfaces can be bridged with your LAN, allowing the same subnet to be used on both sides (with fully working ARP), which is what you originally asked for.






                      share|improve this answer






























                        0














                        First problem: You are trying to use an address which is local to your subnet. Same-subnet traffic does not go through the router and is not affected by the router's firewall rules. When other computers in your LAN want to reach 192.168.1.225, they instead immediately send local ARP queries to learn its MAC address.



                        This can be avoided by using a different subnet for the AWS host, or by configuring Proxy-ARP on the router, making it spoof the ARP responses for that address.



                        Second problem: IP packets can only carry one destination, so DNAT loses information – the recipient (your local router) no longer knows what the original destination was supposed to be. (Only the same host which performed the translation has this information.) So the AWS host can DNAT a single destination to your local public address, but cannot DNAT a whole /24.



                        To avoid this, you need to tunnel the packets – instead of translating them, encapsulate the original packet within a second IP header. (Also called a VPN.) There are many options for configuring a tunnel on Linux, from plain IPIP or GRE to IPsec to WireGuard or Tinc or OpenVPN.



                        Most tunnel/VPN types are L3 (they carry IP packets inside), so you will still need to use a different subnet number from the regular LAN subnet, and have the router actually route between LAN interface and VPN/tunnel interface.



                        Some tunnels support L2 mode (carry Ethernet frames inside), e.g. EoIP, gretap, OpenVPN --dev-type tap, ZeroTier. These L2 tunnel interfaces can be bridged with your LAN, allowing the same subnet to be used on both sides (with fully working ARP), which is what you originally asked for.






                        share|improve this answer




























                          0












                          0








                          0







                          First problem: You are trying to use an address which is local to your subnet. Same-subnet traffic does not go through the router and is not affected by the router's firewall rules. When other computers in your LAN want to reach 192.168.1.225, they instead immediately send local ARP queries to learn its MAC address.



                          This can be avoided by using a different subnet for the AWS host, or by configuring Proxy-ARP on the router, making it spoof the ARP responses for that address.



                          Second problem: IP packets can only carry one destination, so DNAT loses information – the recipient (your local router) no longer knows what the original destination was supposed to be. (Only the same host which performed the translation has this information.) So the AWS host can DNAT a single destination to your local public address, but cannot DNAT a whole /24.



                          To avoid this, you need to tunnel the packets – instead of translating them, encapsulate the original packet within a second IP header. (Also called a VPN.) There are many options for configuring a tunnel on Linux, from plain IPIP or GRE to IPsec to WireGuard or Tinc or OpenVPN.



                          Most tunnel/VPN types are L3 (they carry IP packets inside), so you will still need to use a different subnet number from the regular LAN subnet, and have the router actually route between LAN interface and VPN/tunnel interface.



                          Some tunnels support L2 mode (carry Ethernet frames inside), e.g. EoIP, gretap, OpenVPN --dev-type tap, ZeroTier. These L2 tunnel interfaces can be bridged with your LAN, allowing the same subnet to be used on both sides (with fully working ARP), which is what you originally asked for.






                          share|improve this answer















                          First problem: You are trying to use an address which is local to your subnet. Same-subnet traffic does not go through the router and is not affected by the router's firewall rules. When other computers in your LAN want to reach 192.168.1.225, they instead immediately send local ARP queries to learn its MAC address.



                          This can be avoided by using a different subnet for the AWS host, or by configuring Proxy-ARP on the router, making it spoof the ARP responses for that address.



                          Second problem: IP packets can only carry one destination, so DNAT loses information – the recipient (your local router) no longer knows what the original destination was supposed to be. (Only the same host which performed the translation has this information.) So the AWS host can DNAT a single destination to your local public address, but cannot DNAT a whole /24.



                          To avoid this, you need to tunnel the packets – instead of translating them, encapsulate the original packet within a second IP header. (Also called a VPN.) There are many options for configuring a tunnel on Linux, from plain IPIP or GRE to IPsec to WireGuard or Tinc or OpenVPN.



                          Most tunnel/VPN types are L3 (they carry IP packets inside), so you will still need to use a different subnet number from the regular LAN subnet, and have the router actually route between LAN interface and VPN/tunnel interface.



                          Some tunnels support L2 mode (carry Ethernet frames inside), e.g. EoIP, gretap, OpenVPN --dev-type tap, ZeroTier. These L2 tunnel interfaces can be bridged with your LAN, allowing the same subnet to be used on both sides (with fully working ARP), which is what you originally asked for.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 10 at 18:08

























                          answered Feb 10 at 17:27









                          grawitygrawity

                          240k37508561




                          240k37508561






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404175%2froute-so-that-aws-instance-appears-on-internal-network-and-vice-versa%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Probability when a professor distributes a quiz and homework assignment to a class of n students.

                              Aardman Animations

                              Are they similar matrix