# FreeBSD Port-Forwarding With PF?



## markcoker (Apr 3, 2010)

FreeBSD Port-Forwarding With PF?

I new to FreeBSD, wanted to know how to forward ports, im assuming i have to edit pf.conf.

Basicly i wanted to used utorrent and call of duty mod2, but i really just want learn the process.

Thanks in advance ps. The ports needed are 1500,3005,3101,28960,27015 and a random port for utorrent like 121247.

Ive tried the follow...
then typed `/etc/rc.d/pf reload`
(Reloading pf rules.)


```
tcp_services="{ 1500,2390,2049,3005,3101,27015,28960 }"
udp_services="{ 1500,2390,2049,3005,3101,27015,28960 }"
icmp_types="echoreq"

comp3="192.168.1.109"

rdr on $ext_if proto tcp from any to any port 1500 -> $comp3
rdr on $ext_if proto tcp from any to any port 2390 -> $comp3
rdr on $ext_if proto tcp from any to any port 2049 -> $comp3
rdr on $ext_if proto tcp from any to any port 3005 -> $comp3
rdr on $ext_if proto tcp from any to any port 3101 -> $comp3
rdr on $ext_if proto tcp from any to any port 27015 -> $comp3
rdr on $ext_if proto tcp from any to any port 28960 -> $comp3

rdr on $ext_if proto udp from any to any port 1500 -> $comp3
rdr on $ext_if proto udp from any to any port 2390 -> $comp3
rdr on $ext_if proto udp from any to any port 2049 -> $comp3
rdr on $ext_if proto udp from any to any port 3005 -> $comp3
rdr on $ext_if proto udp from any to any port 3101 -> $comp3
rdr on $ext_if proto udp from any to any port 27015 -> $comp3
rdr on $ext_if proto udp from any to any port 28960 -> $comp3
```


----------



## SirDice (Apr 3, 2010)

How about making use of those variables?


```
myservices="{ 1500,2390,2049,3005,3101,27015,28960 }"

comp3="192.168.1.109"

rdr on $ext_if proto udp/tcp from any to any port $myservices -> $comp3
```


----------



## markcoker (Apr 4, 2010)

SirDice said:
			
		

> How about making use of those variables?
> 
> 
> ```
> ...



thanks lots!, but theres a Syntax error in " rdr on $ext_if proto udp/tcp from any to any port $myservices -> $comp3 "


----------



## dennylin93 (Apr 4, 2010)

Replace udp/tcp with either tcp or udp.


----------



## markcoker (Apr 4, 2010)

I tried that but this happens,


```
# /etc/rc.d/pf reload
Reloading pf rules.
/etc/pf.conf:229: Rules must be in order: options, normalization, queueing, translation, filtering
pfctl: Syntax error in config file: pf rules not loaded
```




```
# FILTERING SECTION
# -----------------

#block everything unless it passes a rule later
block in on $ext_if all
block out on $ext_if all
block in on $int_if all
block out on $int_if all

myservices="{ 1500,2390,2049,3005,3101,27015,28960 }"

comp3="192.168.1.109"

#rdr on $ext_if proto udp from any to any port $myservices -> $comp3 (current disabled not sure if i can do both udp & tcp)
rdr on $ext_if proto tcp from any to any port $myservices -> $comp3
```

Thanks again much appreciated.


----------



## markcoker (Apr 4, 2010)

sorry, i missed a few lines rules. now it loads fine but ports are still not open any ideas?


----------



## SirDice (Apr 4, 2010)

Ah.. I see the typo..


```
myservices="{ 1500,2390,2049,3005,3101,27015,28960 }"

comp3="192.168.1.109"

rdr on $ext_if proto {udp, tcp} from any to any port $myservices -> $comp3

pass in on $ext_if proto {udp, tcp} from any to any port $myservices keep state
```

The order needs to be correct. It's *nat* first, then the *rdr* and lastly any *block* or *pass* rules.


----------



## markcoker (Apr 4, 2010)

noway!, we did it  thanks it works great and i understand the process alot more .


----------



## sniper007 (Apr 4, 2010)

you can also create all in one rule like this:

```
rdr pass on $ext_if proto { tcp, udp } from any to any port $myservices -> $comp3
```


----------

