# How to add rule in PF without writing in pf.conf



## udaycdac (Mar 19, 2012)

*C*an anyone tell me how to add rules in PF using pfctl without writing in pf.conf.


----------



## SirDice (Mar 19, 2012)

Using anchors is probably the easiest.


```
anchor myanchor
```

You can then add rules, which will be added at the position the anchor is in:

```
echo "block in from 1.2.3.4 to any" | pcftl -a myanchor -f -
```

See pf.conf(5).


----------



## udaycdac (Mar 19, 2012)

Thanx Sir for responding. *I* added rules in Iptables. *I*s there any direct command for adding the rules. *C*an u you give me an example?


----------



## SirDice (Mar 19, 2012)

IPTables is Linux.


----------



## melancholicpenguin (Mar 22, 2013)

I have a similar question. Want to update running firewall with additional nat/rule to forward port based on an external event.

I assume `# pfctl -f /tmp/rules.update` can be used but will it affect the currently running configuration already loaded from /etc/pf.conf?


----------



## SirDice (Mar 22, 2013)

melancholicpenguin said:
			
		

> I assume `# pfctl -f /tmp/rules.update` can be used but will it affect the currently running configuration already loaded from /etc/pf.conf?


Yes, the rules will be loaded from /tmp/rules.update but current states will not be affected.


----------



## udaycdac (Apr 1, 2013)

*I* found the solution using the py-pf library in Python.


----------

