How to allow external networks connect via ssh to the internal server using iptables [closed]

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











up vote
1
down vote

favorite
1












I am having a firewall with the IP of 10.0.0.2/24 which is the default gateway as well. I need to allow external networks to be able to SSH to the Server which its IP is 10.0.0.1/24. I have to use iptables and I need to set the permissions on the firewall. Can you please help me out?







share|improve this question














closed as unclear what you're asking by Rui F Ribeiro, jayhendren, roaima, mdpc, Fox Jan 6 at 0:40


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
    – Thomas Ward
    Jan 5 at 19:30










  • I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
    – Marvic Grima
    Jan 5 at 19:34










  • 10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
    – cricket_007
    Jan 5 at 19:52











  • Yes it is the LAN subnet but I want external access on any network.
    – Marvic Grima
    Jan 5 at 19:54














up vote
1
down vote

favorite
1












I am having a firewall with the IP of 10.0.0.2/24 which is the default gateway as well. I need to allow external networks to be able to SSH to the Server which its IP is 10.0.0.1/24. I have to use iptables and I need to set the permissions on the firewall. Can you please help me out?







share|improve this question














closed as unclear what you're asking by Rui F Ribeiro, jayhendren, roaima, mdpc, Fox Jan 6 at 0:40


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
    – Thomas Ward
    Jan 5 at 19:30










  • I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
    – Marvic Grima
    Jan 5 at 19:34










  • 10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
    – cricket_007
    Jan 5 at 19:52











  • Yes it is the LAN subnet but I want external access on any network.
    – Marvic Grima
    Jan 5 at 19:54












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I am having a firewall with the IP of 10.0.0.2/24 which is the default gateway as well. I need to allow external networks to be able to SSH to the Server which its IP is 10.0.0.1/24. I have to use iptables and I need to set the permissions on the firewall. Can you please help me out?







share|improve this question














I am having a firewall with the IP of 10.0.0.2/24 which is the default gateway as well. I need to allow external networks to be able to SSH to the Server which its IP is 10.0.0.1/24. I have to use iptables and I need to set the permissions on the firewall. Can you please help me out?









share|improve this question













share|improve this question




share|improve this question








edited Jan 6 at 1:22

























asked Jan 5 at 19:27









Marvic Grima

92




92




closed as unclear what you're asking by Rui F Ribeiro, jayhendren, roaima, mdpc, Fox Jan 6 at 0:40


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Rui F Ribeiro, jayhendren, roaima, mdpc, Fox Jan 6 at 0:40


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
    – Thomas Ward
    Jan 5 at 19:30










  • I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
    – Marvic Grima
    Jan 5 at 19:34










  • 10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
    – cricket_007
    Jan 5 at 19:52











  • Yes it is the LAN subnet but I want external access on any network.
    – Marvic Grima
    Jan 5 at 19:54
















  • i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
    – Thomas Ward
    Jan 5 at 19:30










  • I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
    – Marvic Grima
    Jan 5 at 19:34










  • 10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
    – cricket_007
    Jan 5 at 19:52











  • Yes it is the LAN subnet but I want external access on any network.
    – Marvic Grima
    Jan 5 at 19:54















i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
– Thomas Ward
Jan 5 at 19:30




i'm confused. The server you want to allow external networks to SSH to, is it at the border of the network or is it behind another system that acts as a firewall to filter traffic into and out of the network?
– Thomas Ward
Jan 5 at 19:30












I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
– Marvic Grima
Jan 5 at 19:34




I want to allow external networks to SSH on 10.0.0.1 which is Samba server. The firewall and the server are all on the same nerwork 10.0.0.0/24. It acts as a firewall and I want to set this permission on it.
– Marvic Grima
Jan 5 at 19:34












10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
– cricket_007
Jan 5 at 19:52





10.0.0.0/24 is a LAN subnet, yes? If you want external access, you need to find the WAN address
– cricket_007
Jan 5 at 19:52













Yes it is the LAN subnet but I want external access on any network.
– Marvic Grima
Jan 5 at 19:54




Yes it is the LAN subnet but I want external access on any network.
– Marvic Grima
Jan 5 at 19:54










2 Answers
2






active

oldest

votes

















up vote
2
down vote













You will need to ensure two rules exist on the firewall, assuming everything else is in place:



  1. Forwarding rules: traffic must be allowed to be forwarded to 10.0.0.1 port 22 from the outside.

  2. NAT rules: since you are working with an RFC 1918 private IPv4 network, you will need to change the destination address of packets that arrive at the firewall destined for port 22.

Again, I'm assuming that your firewall is set up to masquerade WAN-bound traffic, has IPv4 forwarding enabled, and will allow the return traffic to be forwarded.



To address the first part to ensure forwarding is allowed:



iptables -I FORWARD -d 10.0.0.1 --p TCP --dport 22 -j ACCEPT


This rule may be unnecessary if your FORWARD chain defaults to ACCEPT (usually the default).



Second, to perform destination address translation:



iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 10.0.0.1


In both examples, I've used -I to ensure the rules are inserted first in their respective chains; taking precedence over any existing rules. This may or may not be desirable.



You can make the rules more specific by adding interface names, but you did not specify any in the question.



Also note that these rules are not persistent; a system reboot will make them disappear.






share|improve this answer



























    up vote
    0
    down vote













    By using the permissions below I was able to ssh externally to an internal network.



    # nano /etc/sysctl.conf

    net.ipv4.ip_forward = 1

    # route add -net 10.0.0.0/24 dev ens33
    # iptables -t nat -A POSTROUTING ! -d 10.0.0.0/24 -o ens33 -j SNAT --to-source 192.168.1.200
    # iptables -A PREROUTING -t nat -i ens38 -p tcp --dport 22 -j DNAT --to 10.0.0.1
    # iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 22 -j ACCEPT





    share|improve this answer





























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      You will need to ensure two rules exist on the firewall, assuming everything else is in place:



      1. Forwarding rules: traffic must be allowed to be forwarded to 10.0.0.1 port 22 from the outside.

      2. NAT rules: since you are working with an RFC 1918 private IPv4 network, you will need to change the destination address of packets that arrive at the firewall destined for port 22.

      Again, I'm assuming that your firewall is set up to masquerade WAN-bound traffic, has IPv4 forwarding enabled, and will allow the return traffic to be forwarded.



      To address the first part to ensure forwarding is allowed:



      iptables -I FORWARD -d 10.0.0.1 --p TCP --dport 22 -j ACCEPT


      This rule may be unnecessary if your FORWARD chain defaults to ACCEPT (usually the default).



      Second, to perform destination address translation:



      iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 10.0.0.1


      In both examples, I've used -I to ensure the rules are inserted first in their respective chains; taking precedence over any existing rules. This may or may not be desirable.



      You can make the rules more specific by adding interface names, but you did not specify any in the question.



      Also note that these rules are not persistent; a system reboot will make them disappear.






      share|improve this answer
























        up vote
        2
        down vote













        You will need to ensure two rules exist on the firewall, assuming everything else is in place:



        1. Forwarding rules: traffic must be allowed to be forwarded to 10.0.0.1 port 22 from the outside.

        2. NAT rules: since you are working with an RFC 1918 private IPv4 network, you will need to change the destination address of packets that arrive at the firewall destined for port 22.

        Again, I'm assuming that your firewall is set up to masquerade WAN-bound traffic, has IPv4 forwarding enabled, and will allow the return traffic to be forwarded.



        To address the first part to ensure forwarding is allowed:



        iptables -I FORWARD -d 10.0.0.1 --p TCP --dport 22 -j ACCEPT


        This rule may be unnecessary if your FORWARD chain defaults to ACCEPT (usually the default).



        Second, to perform destination address translation:



        iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 10.0.0.1


        In both examples, I've used -I to ensure the rules are inserted first in their respective chains; taking precedence over any existing rules. This may or may not be desirable.



        You can make the rules more specific by adding interface names, but you did not specify any in the question.



        Also note that these rules are not persistent; a system reboot will make them disappear.






        share|improve this answer






















          up vote
          2
          down vote










          up vote
          2
          down vote









          You will need to ensure two rules exist on the firewall, assuming everything else is in place:



          1. Forwarding rules: traffic must be allowed to be forwarded to 10.0.0.1 port 22 from the outside.

          2. NAT rules: since you are working with an RFC 1918 private IPv4 network, you will need to change the destination address of packets that arrive at the firewall destined for port 22.

          Again, I'm assuming that your firewall is set up to masquerade WAN-bound traffic, has IPv4 forwarding enabled, and will allow the return traffic to be forwarded.



          To address the first part to ensure forwarding is allowed:



          iptables -I FORWARD -d 10.0.0.1 --p TCP --dport 22 -j ACCEPT


          This rule may be unnecessary if your FORWARD chain defaults to ACCEPT (usually the default).



          Second, to perform destination address translation:



          iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 10.0.0.1


          In both examples, I've used -I to ensure the rules are inserted first in their respective chains; taking precedence over any existing rules. This may or may not be desirable.



          You can make the rules more specific by adding interface names, but you did not specify any in the question.



          Also note that these rules are not persistent; a system reboot will make them disappear.






          share|improve this answer












          You will need to ensure two rules exist on the firewall, assuming everything else is in place:



          1. Forwarding rules: traffic must be allowed to be forwarded to 10.0.0.1 port 22 from the outside.

          2. NAT rules: since you are working with an RFC 1918 private IPv4 network, you will need to change the destination address of packets that arrive at the firewall destined for port 22.

          Again, I'm assuming that your firewall is set up to masquerade WAN-bound traffic, has IPv4 forwarding enabled, and will allow the return traffic to be forwarded.



          To address the first part to ensure forwarding is allowed:



          iptables -I FORWARD -d 10.0.0.1 --p TCP --dport 22 -j ACCEPT


          This rule may be unnecessary if your FORWARD chain defaults to ACCEPT (usually the default).



          Second, to perform destination address translation:



          iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 10.0.0.1


          In both examples, I've used -I to ensure the rules are inserted first in their respective chains; taking precedence over any existing rules. This may or may not be desirable.



          You can make the rules more specific by adding interface names, but you did not specify any in the question.



          Also note that these rules are not persistent; a system reboot will make them disappear.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 5 at 20:32









          multithr3at3d

          37618




          37618






















              up vote
              0
              down vote













              By using the permissions below I was able to ssh externally to an internal network.



              # nano /etc/sysctl.conf

              net.ipv4.ip_forward = 1

              # route add -net 10.0.0.0/24 dev ens33
              # iptables -t nat -A POSTROUTING ! -d 10.0.0.0/24 -o ens33 -j SNAT --to-source 192.168.1.200
              # iptables -A PREROUTING -t nat -i ens38 -p tcp --dport 22 -j DNAT --to 10.0.0.1
              # iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 22 -j ACCEPT





              share|improve this answer


























                up vote
                0
                down vote













                By using the permissions below I was able to ssh externally to an internal network.



                # nano /etc/sysctl.conf

                net.ipv4.ip_forward = 1

                # route add -net 10.0.0.0/24 dev ens33
                # iptables -t nat -A POSTROUTING ! -d 10.0.0.0/24 -o ens33 -j SNAT --to-source 192.168.1.200
                # iptables -A PREROUTING -t nat -i ens38 -p tcp --dport 22 -j DNAT --to 10.0.0.1
                # iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 22 -j ACCEPT





                share|improve this answer
























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  By using the permissions below I was able to ssh externally to an internal network.



                  # nano /etc/sysctl.conf

                  net.ipv4.ip_forward = 1

                  # route add -net 10.0.0.0/24 dev ens33
                  # iptables -t nat -A POSTROUTING ! -d 10.0.0.0/24 -o ens33 -j SNAT --to-source 192.168.1.200
                  # iptables -A PREROUTING -t nat -i ens38 -p tcp --dport 22 -j DNAT --to 10.0.0.1
                  # iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 22 -j ACCEPT





                  share|improve this answer














                  By using the permissions below I was able to ssh externally to an internal network.



                  # nano /etc/sysctl.conf

                  net.ipv4.ip_forward = 1

                  # route add -net 10.0.0.0/24 dev ens33
                  # iptables -t nat -A POSTROUTING ! -d 10.0.0.0/24 -o ens33 -j SNAT --to-source 192.168.1.200
                  # iptables -A PREROUTING -t nat -i ens38 -p tcp --dport 22 -j DNAT --to 10.0.0.1
                  # iptables -A FORWARD -p tcp -d 10.0.0.1 --dport 22 -j ACCEPT






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 6 at 8:26









                  Zanna

                  2,4311023




                  2,4311023










                  answered Jan 6 at 0:35









                  Marvic Grima

                  92




                  92












                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)