Port redirection to 127.0.0.1 in network namespace with iptables

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












I use custom protocol server inside network namespace. It listens for some port on localhost only. Network namespace contains virtual Ethernet device with IP 192.168.0.2. I want to redirect incoming packets to 192.168.0.2 to my custom server. I use following iptables configuration in my network namespace:



# Filter settings. We are isolated virtual network, so we allow all
*filter
:INPUT ACCEPT
:FORWARD ACCEPT
:OUTPUT ACCEPT
COMMIT

# NAT settings
*nat
:PREROUTING ACCEPT
:INPUT ACCEPT
:OUTPUT ACCEPT
:POSTROUTING ACCEPT

# Required to forward
-A POSTROUTING -j MASQUERADE

# Forward external IP to custom server
-A PREROUTING -d 192.168.0.2 -p tcp -m tcp --dport 1080:1095 -j DNAT --to-destination 127.0.0.1:1080-1095

COMMIT


I set following environment variables:



net.ipv4.ip_forward=1
net.ipv4.conf.veth1.route_localnet=1
net.ipv4.conf.veth1.log_martians=1


Forwarding doesn't work for any reason.



Does anyone know how to forward incoming veth packets to lo in network namespace?







share|improve this question
























    up vote
    0
    down vote

    favorite












    I use custom protocol server inside network namespace. It listens for some port on localhost only. Network namespace contains virtual Ethernet device with IP 192.168.0.2. I want to redirect incoming packets to 192.168.0.2 to my custom server. I use following iptables configuration in my network namespace:



    # Filter settings. We are isolated virtual network, so we allow all
    *filter
    :INPUT ACCEPT
    :FORWARD ACCEPT
    :OUTPUT ACCEPT
    COMMIT

    # NAT settings
    *nat
    :PREROUTING ACCEPT
    :INPUT ACCEPT
    :OUTPUT ACCEPT
    :POSTROUTING ACCEPT

    # Required to forward
    -A POSTROUTING -j MASQUERADE

    # Forward external IP to custom server
    -A PREROUTING -d 192.168.0.2 -p tcp -m tcp --dport 1080:1095 -j DNAT --to-destination 127.0.0.1:1080-1095

    COMMIT


    I set following environment variables:



    net.ipv4.ip_forward=1
    net.ipv4.conf.veth1.route_localnet=1
    net.ipv4.conf.veth1.log_martians=1


    Forwarding doesn't work for any reason.



    Does anyone know how to forward incoming veth packets to lo in network namespace?







    share|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use custom protocol server inside network namespace. It listens for some port on localhost only. Network namespace contains virtual Ethernet device with IP 192.168.0.2. I want to redirect incoming packets to 192.168.0.2 to my custom server. I use following iptables configuration in my network namespace:



      # Filter settings. We are isolated virtual network, so we allow all
      *filter
      :INPUT ACCEPT
      :FORWARD ACCEPT
      :OUTPUT ACCEPT
      COMMIT

      # NAT settings
      *nat
      :PREROUTING ACCEPT
      :INPUT ACCEPT
      :OUTPUT ACCEPT
      :POSTROUTING ACCEPT

      # Required to forward
      -A POSTROUTING -j MASQUERADE

      # Forward external IP to custom server
      -A PREROUTING -d 192.168.0.2 -p tcp -m tcp --dport 1080:1095 -j DNAT --to-destination 127.0.0.1:1080-1095

      COMMIT


      I set following environment variables:



      net.ipv4.ip_forward=1
      net.ipv4.conf.veth1.route_localnet=1
      net.ipv4.conf.veth1.log_martians=1


      Forwarding doesn't work for any reason.



      Does anyone know how to forward incoming veth packets to lo in network namespace?







      share|improve this question












      I use custom protocol server inside network namespace. It listens for some port on localhost only. Network namespace contains virtual Ethernet device with IP 192.168.0.2. I want to redirect incoming packets to 192.168.0.2 to my custom server. I use following iptables configuration in my network namespace:



      # Filter settings. We are isolated virtual network, so we allow all
      *filter
      :INPUT ACCEPT
      :FORWARD ACCEPT
      :OUTPUT ACCEPT
      COMMIT

      # NAT settings
      *nat
      :PREROUTING ACCEPT
      :INPUT ACCEPT
      :OUTPUT ACCEPT
      :POSTROUTING ACCEPT

      # Required to forward
      -A POSTROUTING -j MASQUERADE

      # Forward external IP to custom server
      -A PREROUTING -d 192.168.0.2 -p tcp -m tcp --dport 1080:1095 -j DNAT --to-destination 127.0.0.1:1080-1095

      COMMIT


      I set following environment variables:



      net.ipv4.ip_forward=1
      net.ipv4.conf.veth1.route_localnet=1
      net.ipv4.conf.veth1.log_martians=1


      Forwarding doesn't work for any reason.



      Does anyone know how to forward incoming veth packets to lo in network namespace?









      share|improve this question











      share|improve this question




      share|improve this question










      asked May 17 at 15:24









      Vitaliy

      1064




      1064

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1037439%2fport-redirection-to-127-0-0-1-in-network-namespace-with-iptables%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1037439%2fport-redirection-to-127-0-0-1-in-network-namespace-with-iptables%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

          Which professions warranted travel in Medieval times?

          Trouble downloading packages list due to a “Hash sum mismatch” error