Firewall on single server RH7.0 - NIC <->modem

Running RH7.0 on an IntelliStation attached to  corp. LAN. via tr0 (9.xx.xx.xx). I have users who telnet into this Linux box via the LAN and use minicom/dip to dial out sl0 (ttyS0).
I want to setup a firewall on this server so that:

All inbound requests on sl0 are denied.
All outbound requests on sl0 except telnet and ftp (port 20/21) are denied.

All inbound requests on tr0 except telnet denied.
All outbound requests on tr0 except telnet and ftp are denied.
Would like your thoughts and examples on this.
Who is Participating?
ahoffmannConnect With a Mentor Commented:
ipchains -A input -i sl0 -j DENY
ipchains -A output -i sl0 --dport ! 20:21 -j DENY
# similar for tr0
dbusherAuthor Commented:
In what file should this go so that it is in effect upon boot up?
write a new rc-script started at boot.
I'm not familar with RH, but usualy this file is i /sbin/init.d or /etc/init.d, then you need a symlink to this file. See README in the directory.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

you may manage rc-scripts with rctab
RedHat doesn't have rctab, I believe. The best place to put the ipchains commands is at the end of /etc/rc.d/init.d/rc.local; this is the last startup script to be executed.

dbusherAuthor Commented:
I just put my ipchain statement right on in that file? I'll give it a shot.
If you want the rules to apply after you restart, just apply the rules on the command line like ahoffman showed above.  You can then save them for the RC scripts by typing "service ipchains save" after you have everything working the way you want.  Voila...
ifinchamConnect With a Mentor Commented:

Don't think its quite as simple as that ! When you allow outbound packets you have to also allow the related inbound packets. Also FTP is a bit more complex because there is a client initiated connection on port 21 but then, for the data, a ftp-server initiated session from the server's port 20 that you have to allow in.

Firstly, 'flush' existing chain and set default :

ipchains -F
ipchains -P input DENY
ipchains -P output DENY
ipchains -P forward DENY

For telnet :

ipchains -A output -i tr0 -p tcp -d any/0 23 -j ACCEPT
ipchains -A input -i tr0 -p tcp ! -y -s any/0 23 -j ACCEPT

For 'normal mode' (not-passive) FTP ;

ipchains -A output -i tr0 -p tcp -d any/0 21 -j ACCEPT
ipchains -A input -i tr0 -p tcp ! -y -s any/0 21 -j ACCEPT
ipchains -A input -i tr0 -p tcp -s any/0 20 -d any/o 1024:65535 -j ACCEPT
ipchains -A output -i tr0 -p tcp ! -y -s any/0 1024:65535 -d any/0 20 -j accept

Obviously, I've just shown the rules for the token-ring interface above... (The '! -y' bit means check that SYN is not set, i.e.  its not an attempt to initiate a connection the other way round)

On storing the rules...

'/sbin/service ipchains save' will place the output into  '/etc/sysconfig/ipchains'. Redhat have a sysv init script called ipchains so you would activate that by setting run-levels 2345 on via 'ntsysv' or even simpler by the following command (as root)

/sbin/chkconfig --level 2345 ipchains on

An alternative would be simply to place the rules in the '/etc/rc.d/rc.local' script which is the last script run in the normal redhat boot sequence.



Actually just noticed there was a difference with the tr0 interface in that you wanted to allow inbound.

THe following allows inbound telnet

ipchains -A input -i tr0 -p tcp -s any/0 1024:65535 -d any/0 23 -j ACCEPT
ipchains -A output -1 tr0 -p tcp ! -y -s any/0 23 -d any/0 1024:65535 -j ACCEPT

Also in case you want passive ftp :

ipchains -A output -i tr0 -p tcp -s any/0 1024:65535 -d any/0 1024:65535 -j ACCEPT
ipchains -A input -i tr0 -p tcp ! -y -s any/0 1024:65535 -d any/0 1024:65535 -j ACCEPT

In fact, you'd be better off substituting 'any/0' for your actual IP address ... For example using as your linux box..

ipchains -A output -i tr0 -p tcp -s 1024:65535 -d any/0 1024:65535 -j ACCEPT
ipchains -A input -i tr0 -p tcp ! -y -s any/0 1024:65535 -d 1024:65535 -j ACCEPT


dbusherAuthor Commented:
I will be away for 2 weeks. I will give each of these a shot when I return.  Sorry for the delay
dbusherAuthor Commented:
My 2 weeks turned out to be much longer.  I will me in the office on the 23rd to give this a shot. If all goes well I will accept at the end of the week. Sorry for the delay and thanks for all the great help.
dbusherAuthor Commented:
ifincham,  it looks like this will allow inbound AND outbound telnet on tr0.  True? Or does the FLUSH take care of this?? Thanks.
Also, How do I reject ALL inbound requests on my modem port ttyS0? Which is sl0. Same type of commands??  Sorry, I am a newbie at this.
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
except a typo (should be -o instead og -i in secind rule) my very first suggestion is still valid
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split between ahoffmann & ifincham.
Please leave any comments here within the next seven days.


EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.