Local port forwarding using iptables is not working

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I am using the following command to forward incoming traffic from port 30 to port 1234. But it's not working. In Wireshark also there is no trace of packets directing to port 1234 are found.



sudo iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 30 -j REDIRECT --to-ports 1234.







share|improve this question



















  • Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
    – Raman Sailopal
    Jul 20 at 9:16










  • Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
    – SRNB
    Jul 20 at 11:30
















up vote
0
down vote

favorite












I am using the following command to forward incoming traffic from port 30 to port 1234. But it's not working. In Wireshark also there is no trace of packets directing to port 1234 are found.



sudo iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 30 -j REDIRECT --to-ports 1234.







share|improve this question



















  • Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
    – Raman Sailopal
    Jul 20 at 9:16










  • Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
    – SRNB
    Jul 20 at 11:30












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using the following command to forward incoming traffic from port 30 to port 1234. But it's not working. In Wireshark also there is no trace of packets directing to port 1234 are found.



sudo iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 30 -j REDIRECT --to-ports 1234.







share|improve this question











I am using the following command to forward incoming traffic from port 30 to port 1234. But it's not working. In Wireshark also there is no trace of packets directing to port 1234 are found.



sudo iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 30 -j REDIRECT --to-ports 1234.









share|improve this question










share|improve this question




share|improve this question









asked Jul 20 at 8:16









SRNB

1




1











  • Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
    – Raman Sailopal
    Jul 20 at 9:16










  • Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
    – SRNB
    Jul 20 at 11:30
















  • Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
    – Raman Sailopal
    Jul 20 at 9:16










  • Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
    – SRNB
    Jul 20 at 11:30















Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
– Raman Sailopal
Jul 20 at 9:16




Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1
– Raman Sailopal
Jul 20 at 9:16












Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
– SRNB
Jul 20 at 11:30




Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work.
– SRNB
Jul 20 at 11:30










2 Answers
2






active

oldest

votes

















up vote
0
down vote













check if this is enabled or not by



sudo iptables -t nat -L


If There are any entries , delete them using:



sudo iptables -F -t nat


Try without src dest flags:



sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234


check again if this is enabled or not by



sudo iptables -t nat -L


It is Important to remove chained entries queued by default to "OUTPUT" route.



Hope This helps!!






share|improve this answer






























    up vote
    0
    down vote













    Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.



    sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.



    More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial






    share|improve this answer





















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      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: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      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%2funix.stackexchange.com%2fquestions%2f457375%2flocal-port-forwarding-using-iptables-is-not-working%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      check if this is enabled or not by



      sudo iptables -t nat -L


      If There are any entries , delete them using:



      sudo iptables -F -t nat


      Try without src dest flags:



      sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234


      check again if this is enabled or not by



      sudo iptables -t nat -L


      It is Important to remove chained entries queued by default to "OUTPUT" route.



      Hope This helps!!






      share|improve this answer



























        up vote
        0
        down vote













        check if this is enabled or not by



        sudo iptables -t nat -L


        If There are any entries , delete them using:



        sudo iptables -F -t nat


        Try without src dest flags:



        sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234


        check again if this is enabled or not by



        sudo iptables -t nat -L


        It is Important to remove chained entries queued by default to "OUTPUT" route.



        Hope This helps!!






        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          check if this is enabled or not by



          sudo iptables -t nat -L


          If There are any entries , delete them using:



          sudo iptables -F -t nat


          Try without src dest flags:



          sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234


          check again if this is enabled or not by



          sudo iptables -t nat -L


          It is Important to remove chained entries queued by default to "OUTPUT" route.



          Hope This helps!!






          share|improve this answer















          check if this is enabled or not by



          sudo iptables -t nat -L


          If There are any entries , delete them using:



          sudo iptables -F -t nat


          Try without src dest flags:



          sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234


          check again if this is enabled or not by



          sudo iptables -t nat -L


          It is Important to remove chained entries queued by default to "OUTPUT" route.



          Hope This helps!!







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 20 at 8:39


























          answered Jul 20 at 8:32









          Pavan Kate

          263




          263






















              up vote
              0
              down vote













              Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.



              sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.



              More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial






              share|improve this answer

























                up vote
                0
                down vote













                Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.



                sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.



                More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.



                  sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.



                  More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial






                  share|improve this answer













                  Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.



                  sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.



                  More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jul 24 at 7:35









                  SRNB

                  1




                  1






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457375%2flocal-port-forwarding-using-iptables-is-not-working%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)