In order to present these questions, I think it's necessary to tell all the following circumstances.
I'm playing with pf on a new server (not in production, no data on it yet, I can reinstall from scratch if necessary, but there's also a "rescue-bsd" mode that lets me mount the filesystems and edit configuration files to repair my mistakes).
First error: I forgot the line in /etc/pf.conf to allow outgoing traffic, so of course I got kicked off of my server. I restarted in rescue mode, added the missing line, restarted from hard disk and I could ssh again into the server. In the meanwhile, the provider of the server sent me a first e-mail telling there was a problem (of course), that they send a technician to handle this... then another mail telling the problem wasn't there any longer, so they don't send anyone. So far, no problem.
After that, I added a line to allow ftp traffic in. So the file, from this:
Became this:
I checked there was no error (
At this point I got kicked off again of my server (the ssh connection has been lost). I don't understand why, this time. Moreover, I could ssh at once again into the server, so I didn't care. It was late, I stopped working, watched a movie. After that, I checked my mails and discovered the provider sent another e-mail telling there was a problem (after the this last reloading of rules)... and that they've sent someone who did a hard-reboot. Since then, no problem anymore (though the same rules are loaded at startup).
Questions:
1. There is still something strange in this outgoing traffic rule, because I allow only tcp and udp traffic, so ping shouldn't work, should it? (ping uses icmp).
2. Soon I will want to add a line to allow tcp traffic on ports 80 and 443. Is there any risk things happen like when I added the line for ftp?
3. All comments and advices about the pf.conf file I use are welcome! (Its goal is to allow only what's necessary: ssh, ftp and later http/https, and what's usually needed from a server)
I'm playing with pf on a new server (not in production, no data on it yet, I can reinstall from scratch if necessary, but there's also a "rescue-bsd" mode that lets me mount the filesystems and edit configuration files to repair my mistakes).
First error: I forgot the line in /etc/pf.conf to allow outgoing traffic, so of course I got kicked off of my server. I restarted in rescue mode, added the missing line, restarted from hard disk and I could ssh again into the server. In the meanwhile, the provider of the server sent me a first e-mail telling there was a problem (of course), that they send a technician to handle this... then another mail telling the problem wasn't there any longer, so they don't send anyone. So far, no problem.
After that, I added a line to allow ftp traffic in. So the file, from this:
Code:
# INTERFACES
# check if ext_if matches the network card name (ifconfig tells it)
ext_if="em0"
# this one has been created for the jails
int_if = "lo1"
jailnet = $int_if:network
# PORTS
ftp_port=...
ssh_default_port=22
ssh_port=...
# IP ADDRESSES
admin_ip="..."
server_ip="..."
ftp_jail_ip="10.1.1.128"
# NORMALIZATION
scrub in all
# NAT
nat on $ext_if from $jailnet to any -> ($ext_if)
# RDR
rdr pass on $ext_if proto tcp from any to $server_ip port $ftp_port -> $ftp_jail_ip port $ftp_port
# INGOING CONNEXIONS blocked by default
block in on $ext_if
# ALLOW SSH FROM ADMIN
pass in on $ext_if proto tcp from $admin_ip to $ext_if port $ssh_default_port
pass in on $ext_if proto tcp from $admin_ip to $ext_if port $ssh_port
# ALLOW OUTGOING TRAFFIC
pass out on $ext_if proto { tcp, udp } all
Became this:
Code:
# INTERFACES
# check if ext_if matches the network card name (ifconfig tells it)
ext_if="em0"
# this one has been created for the jails
int_if = "lo1"
jailnet = $int_if:network
# PORTS
ftp_port=...
ssh_default_port=22
ssh_port=...
# IP ADDRESSES
admin_ip="..."
server_ip="..."
ftp_jail_ip="10.1.1.128"
# NORMALIZATION
scrub in all
# NAT
nat on $ext_if from $jailnet to any -> ($ext_if)
# RDR
rdr pass on $ext_if proto tcp from any to $server_ip port $ftp_port -> $ftp_jail_ip port $ftp_port
# INGOING CONNEXIONS blocked by default
block in on $ext_if
# ALLOW SSH FROM ADMIN
pass in on $ext_if proto tcp from $admin_ip to $ext_if port $ssh_default_port
pass in on $ext_if proto tcp from $admin_ip to $ext_if port $ssh_port
# ALLOW FTP FROM ANY IP
pass in on $ext_if proto tcp from any to $ext_if port $ftp_port
# ALLOW OUTGOING TRAFFIC
pass out on $ext_if proto { tcp, udp } all
I checked there was no error (
pfctl -vnf /etc/pf.conf
) and then reloaded the rules. ( pfctl -F all -f /etc/pf.conf
).At this point I got kicked off again of my server (the ssh connection has been lost). I don't understand why, this time. Moreover, I could ssh at once again into the server, so I didn't care. It was late, I stopped working, watched a movie. After that, I checked my mails and discovered the provider sent another e-mail telling there was a problem (after the this last reloading of rules)... and that they've sent someone who did a hard-reboot. Since then, no problem anymore (though the same rules are loaded at startup).
Questions:
1. There is still something strange in this outgoing traffic rule, because I allow only tcp and udp traffic, so ping shouldn't work, should it? (ping uses icmp).
2. Soon I will want to add a line to allow tcp traffic on ports 80 and 443. Is there any risk things happen like when I added the line for ftp?
3. All comments and advices about the pf.conf file I use are welcome! (Its goal is to allow only what's necessary: ssh, ftp and later http/https, and what's usually needed from a server)