Hello everyone!
I have few network services running in jailed configuration on a server, and I use ipfw to protect the server against possible attacks, and to provide its local clients with access to internet.
The goal I want to achieve is redirection of some ports of jailed services to the server external interface. And I actually did it, but I don't really like the way it looks.
Here're the essential part of my ipfw script :
I did some testing when I was writing these rules, and it appeared that :
uname: freebsd 10.3
the rest of the config i consider irrelevant
I have few network services running in jailed configuration on a server, and I use ipfw to protect the server against possible attacks, and to provide its local clients with access to internet.
The goal I want to achieve is redirection of some ports of jailed services to the server external interface. And I actually did it, but I don't really like the way it looks.
Here're the essential part of my ipfw script :
Code:
# configure nat
$ipfw nat 1 config if $wanif redirect_port tcp $jail1ip:80 8080 reset
# translate addresses
$ipfw add nat 1 ip from any to any via $wanif
# check dynamic rules
$ipfw add check-state
# allow port redirects
$ipfw add allow tcp from any to $jail1ip 80 in via $wanif keep-state
# !!! here's the rule i don't like !!!
$ipfw add allow tcp from me 8080 to any out via $wanif keep-state
# ^^^ here's the rule i don't like ^^^
# deny fake established tcp packets
$ipfw add deny log tcp from any to any established
I did some testing when I was writing these rules, and it appeared that :
- When a packet comes from external network to port 8080 of wan interface, nat engine translates the port of that packet, so the source ip and port of the incoming packet are remained the same, and destination ip and port changes, and then ipfw continues processing the packet according to the ruleset after nat rule.
- The rule 'allow port redirects' passes the packet and creates a dynamic rule for future responses for the packet.
- Then something happens in jail, I just skip it.
- The outgoing response packet is allowed using dynamic rule created at point 2.
- Then nat engine translates source ip and port of outgoing packet to those specified in rule 'configure nat', and puts it back into processing with ipfw.
- Then the outgoing packet is processed with the rule I don't like =(
uname: freebsd 10.3
the rest of the config i consider irrelevant