• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Source NAT and port forwarding

Scheduled Pinned Locked Moved NAT
15 Posts 3 Posters 583 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    tramp_sergey @johnpoz
    last edited by Jan 30, 2025, 4:56 PM

    @johnpoz

    All IPs here are just for example.

    Who is starting the conversation? The 2.2.2.2 or the 192.168.2.2 ??
    A client with src 1.1.1.1:<any port>
    2.2.2.2 is WAN port IP address
    192.168.2.2 is a server over the LAN port

    Who is wanting to talk to who on port 22, is it your device on your wan wanting to talk to device on your lan, or is the lan device wanting to talk to the device on your wan. Who is starting the conversation to the other one?
    The client tries to connect to 2.2.2.2:2222.
    The pfsense should NAT the connection with the source IP of the LAN interface to 192.168.2.2:443

    J 1 Reply Last reply Jan 30, 2025, 5:07 PM Reply Quote 0
    • J
      johnpoz LAYER 8 Global Moderator @tramp_sergey
      last edited by johnpoz Jan 30, 2025, 5:10 PM Jan 30, 2025, 5:07 PM

      @tramp_sergey so some public IP out on the internet hits your pfsense wan which your calling 2.2.2.2 on port 22, and you want to forward that to 192.168.2.2 on your pfsense lan

      And you want this to look like this public IP on the internet is coming from your pfsense lan IP 192.168.2.x

      Well none of those Nats you said you tried would work.. As you see in my example the interface is my cam interface.

      So your outbound nat should be on pfsense lan, and the source would be any or whatever source IP out on the internet is going to want to talk to your ssh server that you are forwarding and the destination would be your 192.168.2.2 address, and the nat address would be your Lan Address on pfsense.

      Curious why do you think you need to do this? Does the 192.168.2.2 device not have a gateway set, or is using something other than pfsense as its gateway, or a firewall that won't allow this public IP to talk to it?

      public IP -----> 2.2.2.2:22 (wan) pfsense (lan) 192.168.2.1 ----> 192.168.2.2:22

      Your outbound nat interface is pfsense lan, the nat address is lan address. Now when publicIP hits pfsense wan and pfsense does it port forward to 192.168.2.2:22, the outbound nat in pfsense will change the source IP to 192.168.2.1 (pfsense address) so your 192.168.2.2 will think ssh is coming from 192.168.2.1, when he sends back the answer pfsense will know oh I need to send this back to PublicIP. And to the publicIP it will think the return traffic coming from pfsense 2.2.2.2 wan IP.

      An intelligent man is sometimes forced to be drunk to spend time with his fools
      If you get confused: Listen to the Music Play
      Please don't Chat/PM me for help, unless mod related
      SG-4860 24.11 | Lab VMs 2.7.2, 24.11

      T 1 Reply Last reply Jan 30, 2025, 7:38 PM Reply Quote 0
      • T
        tramp_sergey @johnpoz
        last edited by Jan 30, 2025, 7:38 PM

        @johnpoz If I understand correctly, you mean this configuration
        fe66d465-9aa5-4701-af4c-55a6f41bb127-image.png
        But it doesn't work also. I don't see any packets on the LAN, but logs show that the traffic is passed.

        The scheme is more correct:
        public IP -----> 2.2.2.2:2222 (wan) pfsense (lan) 192.168.2.254 ----> 192.168.2.2:22

        The device has a different default gateway and it's easier to configure NAT than create a static route on the device and other devices in the location.

        J 1 Reply Last reply Jan 30, 2025, 7:52 PM Reply Quote 0
        • S
          SteveITS Galactic Empire @tramp_sergey
          last edited by Jan 30, 2025, 7:44 PM

          @tramp_sergey The source port on Internet connections is normally random so will basically never be "22"...change that to any/*.

          Pre-2.7.2/23.09: Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
          When upgrading, allow 10-15 minutes to restart, or more depending on packages and device speed.
          Upvote 👍 helpful posts!

          1 Reply Last reply Reply Quote 0
          • J
            johnpoz LAYER 8 Global Moderator @tramp_sergey
            last edited by johnpoz Jan 30, 2025, 7:53 PM Jan 30, 2025, 7:52 PM

            @tramp_sergey said in Source NAT and port forwarding:

            But it doesn't work also. I don't see any packets on the LAN, but logs show that the traffic is passed.

            If your not seeing any traffic on your lan then your port forward isn't working.. As mentioned by @SteveITS that source port is wrong..

            Per your updated drawing of mine, the destination hitting pfsense wan IP on 2.2.2.2 is 2222 but that has nothing to do with the source port the public IP sent from, which is almost always going to be some random port 1024 or above.. Can you show your port forward, because if you are calling out source port there, its not going to work..

            An intelligent man is sometimes forced to be drunk to spend time with his fools
            If you get confused: Listen to the Music Play
            Please don't Chat/PM me for help, unless mod related
            SG-4860 24.11 | Lab VMs 2.7.2, 24.11

            T 1 Reply Last reply Jan 30, 2025, 8:05 PM Reply Quote 0
            • T
              tramp_sergey @johnpoz
              last edited by Jan 30, 2025, 8:05 PM

              @johnpoz I don't have rules for port forwarding.
              Do you mean I should have two NAT rules in that case:
              first for ports
              second for IPs
              ?

              S J 2 Replies Last reply Jan 30, 2025, 8:16 PM Reply Quote 0
              • S
                SteveITS Galactic Empire @tramp_sergey
                last edited by Jan 30, 2025, 8:16 PM

                @tramp_sergey NAT rules are port forwards. Here's an example:
                06010cd5-ae9e-469b-bf52-b3989810b757-image.png
                or one with a source defined:
                0ee4d73d-7ecc-4a7f-800c-4696ef55f585-image.png

                Pre-2.7.2/23.09: Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
                When upgrading, allow 10-15 minutes to restart, or more depending on packages and device speed.
                Upvote 👍 helpful posts!

                T 1 Reply Last reply Jan 31, 2025, 7:06 AM Reply Quote 0
                • J
                  johnpoz LAYER 8 Global Moderator @tramp_sergey
                  last edited by johnpoz Jan 30, 2025, 8:21 PM Jan 30, 2025, 8:17 PM

                  @tramp_sergey said in Source NAT and port forwarding:

                  I don't have rules for port forwarding.

                  Well then how do you think traffic from some public IP on the internet hitting your wan is going to get sent to this 192.168.2.2 address on a different port?

                  Here is a port forward I have for my plex server

                  portforward.jpg

                  So some IP on the internet hits my pfsense wan PublicIP.. to port 23040, pfsense forwards that to my box running plex at 192.168.9.10 port 32400

                  But it will only do that if the source IP is in my alias pfb_allowed.. Which is really any IP in the US or belgium currently - and some other IPs that plex uses to validate plex is available, and other ips that check if my plex is up - and if not warns me that plex is down.

                  But some IP out on the internet hitting your wan IP isn't just going to magically get sent to your 192.168.2.2 IP on some other port.

                  An intelligent man is sometimes forced to be drunk to spend time with his fools
                  If you get confused: Listen to the Music Play
                  Please don't Chat/PM me for help, unless mod related
                  SG-4860 24.11 | Lab VMs 2.7.2, 24.11

                  1 Reply Last reply Reply Quote 0
                  • T
                    tramp_sergey @SteveITS
                    last edited by tramp_sergey Jan 31, 2025, 7:08 AM Jan 31, 2025, 7:06 AM

                    @SteveITS @johnpoz I tried to use the port forwarding NAT, it works, but it doesn't change the source IP address to the LAN address and I haven't found any option for that here.
                    a3aa50a3-6405-40c8-b892-c799ced55f63-image.png

                    J 1 Reply Last reply Jan 31, 2025, 7:08 AM Reply Quote 0
                    • J
                      johnpoz LAYER 8 Global Moderator @tramp_sergey
                      last edited by Jan 31, 2025, 7:08 AM

                      @tramp_sergey you need both the port forward and the outbound nat to change it to the IP of pfsense interface on your lan.

                      An intelligent man is sometimes forced to be drunk to spend time with his fools
                      If you get confused: Listen to the Music Play
                      Please don't Chat/PM me for help, unless mod related
                      SG-4860 24.11 | Lab VMs 2.7.2, 24.11

                      T 1 Reply Last reply Jan 31, 2025, 7:12 AM Reply Quote 0
                      • T
                        tramp_sergey @johnpoz
                        last edited by Jan 31, 2025, 7:12 AM

                        @johnpoz I understand the logic now.
                        I've added the rule yet, and it works as expected now.
                        23f9e7e3-9409-40cb-a081-1a46957a3096-image.png
                        Thanks a lot for your help and patience!

                        1 Reply Last reply Reply Quote 0
                        14 out of 15
                        • First post
                          14/15
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                          This community forum collects and processes your personal information.
                          consent.not_received