# set the following to "YES" to turn them on
pf=YES # Packet filter / NAT
- To start pf:
pfctl -e
- To tell pf which file to use (can be reload while running): pfctl -f /etc/pf.conf
- To stop pf: pfctl -d
pfctl -s rules
pfctl -vvqs
# tcpdump -n -e -ttt -r /var/log/pflog port 80
This can be further refined by limiting the display of packets to a certain host and port combination:
# tcpdump -n -e -ttt -r /var/log/pflog port 80 and host 192.168.1.3
The same idea can be applied when reading from the pflog0 interface:
# tcpdump -n -e -ttt -i pflog0 host 192.168.4.2
# Here follows /etc/pf.conf
# Macros: User-defined variables that can hold IP addresses interface names, etc.
ext_if = "bge0"
int_if = "em0"
tcp_allow = "{21 53 80 111 4045:4047 2049 123 143 139 445 993 110 995 smtp submission domain ntp www https 5995 6888 6889 8085 49152:6553}"
udp_allow = "{20 21 53 111 4045:4047 2049 123 110 137 138 995 143 993 8085}"
# By default block everything:
block in all
block out all
# Allow our chosen ports to be open
pass in on $ext_if proto tcp from any to any port $tcp_allow
pass in on $ext_if proto udp from any to any port $udp_allow
pass out on $ext_if from any to any
pass out on $ext_if from any to any
pass in on $ext_if proto icmp from any to any
pass out on $ext_if proto icmp from any to any
# God knows what this does, but it is there
antispoof quick for { lo0 }
# Allow access to the loopback interface on our machine
pass out quick on lo0 from any to any
pass in quick on lo0 from any to any
# Natting
pass out on $ext_if from $int_if:network to any nat-to $ext_if
# Redirecting ports to machines inside network
pass in on $ext_if proto tcp to port 6888 rdr-to 192.168.1.6 port 3389
pass in on $ext_if proto tcp to port 6888 rdr-to 192.168.1.42 port 6000
pass in on $ext_if proto tcp to port 6889 rdr-to 192.168.1.36 port 22
- HOME
~~~~~~~~~~~~~~~
- OpenBSD
- NetBSD
- FreeBSD
- Linux
- Solaris
- Windows
~~~~~~~~~~~~~~~
- Git
- Ansible
- Atlassian
- Network tools
- Qemu
- Virtualbox
- Vim
- Tmux
- Mutt
- STar
~~~~~~~~~~~~~~~
- MySQL
- PostgreSQL
- Postfix
- OpenSSL
- tcpdump
- SSH
~~~~~~~~~~~~~~~
- Packet Filter
- IP Filter
~~~~~~~~~~~~~~~
- Bash
- web-dev
- Hacking
- LINUX DAYS