Sponsored Content
Full Discussion: iptables port forwarding
Operating Systems Linux Red Hat iptables port forwarding Post 303015406 by oidipus on Wednesday 4th of April 2018 09:15:22 AM
Old 04-04-2018
iptables port forwarding

Hello All,
I would like to ask you very kindly with /etc/sysconfig/iptables file

I have to setup port forwarding on RHEL6 router. Users from public network must be able to ssh to servers in private network behind RHEL6 router. Problem is that servers in private network must be isolated.

My boss require that there will not be any possibility of connection from private network to any remote network behind RHEL6 router

I am not able to DROP any traffic coming from private network.

I did setup port forwarding on router from public network to private network easily but I am not able to force router to drop any traffic coming from private network outside unless I break port forwarding.

here is example of my /etc/sysconfig/iptables file. Please help with line which would drop all outgoing traffic from private network but keep port forwarding working.

Code:
cat /etc/sysconfig/iptables
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
#
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT
-A INPUT -p all -j DROP
#
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to-destination 192.168.0.3:22
COMMIT

BTW: (ssh on router is running on port 2222)


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 04-04-2018 at 10:38 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

iptables: forwarding a port

I've been googling for a while now, trying to forward port 3000 to port 80.... In the past I used to DLink router to forward port 3000 to 80. I recently finished (well, is it ever done anyhow?) setting up my linux box and got it acting as a router. I want to continue to run Apache on port 80... (1 Reply)
Discussion started by: meeps
1 Replies

2. UNIX for Advanced & Expert Users

port forwarding

Hi, I have to install an application that has a built in tftp server. Tftp comes in on port 69. As i am not installing this application as a root user i am running into trouble because only the root user can listen to ports < 1024. So changing the port i listen to to one greater than 1023 isn't... (1 Reply)
Discussion started by: imloaded24_7
1 Replies

3. UNIX for Advanced & Expert Users

Port forwarding

Hi I want to set up port forwarding from one network to another network. I already have this configured on the Linux box using iptables. iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 1521 -j DNAT --to 10.218.146.230 iptables -A FORWARD -p tcp -i eth1 -d 10.218.146.230 -j ACCEPT ... (2 Replies)
Discussion started by: slash_blog
2 Replies

4. Solaris

ip and port forwarding in Solaris 10

Hi; I have the following issue: I have a Solaris server running an old applications which connects to an http server in other server at certain port. The thing is that the http server has changed its ip and port and the addres in the app is hard coded and touching the app by now is out of the... (0 Replies)
Discussion started by: ppereira
0 Replies

5. IP Networking

SSH Port Forwarding - sharing the same port

Hi Linux/Unix Guru, I am setting Linux Hopping Station to another different servers. My current config to connect to another servers is using different port to connect. e.g ssh -D 1080 -p 22 username@server1.com ssh -D 1081 -p 22 username@server2.com Now what I would like to have... (3 Replies)
Discussion started by: regmaster
3 Replies

6. UNIX for Advanced & Expert Users

Iptable and port forwarding

Hello, I have a routeur linksys (192.168.1.1 ) a firewall (192.168.1.55 IN ----> 192.168.2.254 OUT) which using iptable I want to acces to an equipment (lorex video camera serveur 192.168.2.44) which using an ddns service on the port 9000 So i don t know which redirection a will do on the... (2 Replies)
Discussion started by: tapharule
2 Replies

7. IP Networking

iptables port forwarding does not work while I have 2 routes

Hi, On my linux server I have 2 routes: Code: nexthop via 123.201.254.5 dev eth0 weight 38 nexthop via 111.93.155.149 dev eth2 weight 36 I have a iptable rule like : iptables -t nat -A PREROUTING -p tcp -i eth0 -d... (5 Replies)
Discussion started by: ashokvpp
5 Replies

8. UNIX for Dummies Questions & Answers

Iptables, port forwarding, 64k connection limit?

I am having an issue with iptables. My server is a RHEL6 64bit system. In my application I have a large number of connected clients ~100k to a particular service. The application works fine when iptables is off, 100k clients are able to connect. However, when I turn iptables on and add a... (1 Reply)
Discussion started by: jtipp3tt
1 Replies

9. UNIX for Advanced & Expert Users

Help on port forwarding please..

Hi experts, We have windows machine ( A ) in one network & 2 Linux Servers ( B & C ) in another network. There is a firewall between these 2 networks and SSH (TCP/22) & HTTPS (TCP/443) are allowed from A to B only (but not to C). There is no personal firewall / iptables running on any machine.... (1 Reply)
Discussion started by: magnus29
1 Replies

10. IP Networking

Port Forwarding not working

Hello Gurus, I have configured port forwarding at router. But after configuration I am not able to connect the computer from outside/Over internet/Remote desktp from other computer. Could you please advice? Thanks- Pokhraj (2 Replies)
Discussion started by: pokhraj_d
2 Replies
uruk(8) 						      SYSTEM ADMINISTRATION							   uruk(8)

  NAME
      uruk - wrapper for Linux iptables, for managing firewall rules

  SYNOPSIS
      uruk

  DESCRIPTION
      uruk  loads an rc file (see uruk-rc(5)) which defines network service access policy, and invokes iptables(8) to set up firewall rules imple-
      menting this policy. By default the file /etc/uruk/rc is used; one can overrule this by specifying another file in the URUK_CONFIG  environ-
      ment  variable. Under some circumstances, it's useful to use another command for iptables; this can be achieved by setting the URUK_IPTABLES
      (and/or URUK_IP6TABLES) environment variables. See uruk-rc(5) for details.

  QUICK SETUP GUIDE
      Uruk will not "just work" out of the box. It needs manual configuration.	For those of you who don't like reading lots of documentation:

       # cp /usr/share/doc/uruk/examples/rc 
	   /etc/uruk/rc
       # vi /etc/uruk/rc
       # /etc/init.d/uruk start

  GETTING STARTED
      Once the uruk script is installed, you want to go use it, of course. We'll give a detailed description of what to do here.

      First, create an rc file. See uruk-rc(5) for info on how to do this. Once  this  file  is  created  and  installed  (this  script  looks	in
      /etc/uruk/rc by default), you're ready to run uruk. You might want to test your rc file by running uruk in debug mode, see uruk-rc(5).

      Vanilla iptables
      After editing rc, load your rules like this. First flush your current rules:

       # iptables -F
       # ip6tables -F

      Then enable your rc rules

       # uruk

      . Inspect the rules by doing:

       # iptables -L
       # ip6tables -L

      .  If you want to make these changes survive a reboot, use the init script as shipped with this package. If you'd rather write your own init
      script, the iptables-restore(8) and iptables-save(8) commands from the iptables package might be helpful.

      Using the Uruk init script
      Assumed is the Uruk init script is installed as explained in the	README	file.	Optionally,  install  /etc/default/uruk  (or  /etc/syscon-
      fig/uruk)  and  tweak  it.  An example file is in /usr/share/doc/uruk/examples/default (You might like to enable support for uruk-save.) Now
      activate uruk by doing:

       # /etc/init.d/uruk start

      Now your pre-uruk iptables rules (if any) are saved as the "inactive" ruleset.  While executing /etc/init.d/uruk start,  your  box  is  open
      during a short while.  If you don't like this, read below about uruk-save.

      When  rebooting,	everything will be fine: /etc/init.d/uruk stores state in /var/lib/uruk/iptables, using iptables-save(8), which comes with
      Linux iptables.

      Using Debian ifupdown
      In case you have just one network interface which should get protected, you could use interfaces(5) from the Debian ifupdown package instead
      of  the init script. Suppose you'd like to protect ppp0, and would like not to interfere with traffic on eth0: your other network interface.
      First write an rc file. Be sure it features

       interfaces_unprotect="lo eth0"

      Then run:

       # mkdir -p /var/lib/uruk/iptables

       # iptables -F

       # iptables-save -c > /var/lib/uruk/iptables/down
       # uruk
       # iptables-save -c > /var/lib/uruk/iptables/up

      Add

       pre-up iptables-restore < /var/lib/uruk/iptables/up
       post-down iptables-restore < /var/lib/uruk/iptables/down

      to your interfaces stanza, in your /etc/network/interfaces .

      Similar tricks might be possible on GNU/Linux systems from other distributions.  The author is interested.

  LOADING A NEW rc FILE
      Need to change your rules?

      Using the Uruk init script
      Do

       # vi /etc/uruk/rc
       # /etc/init.d/uruk force-reload

      While executing /etc/init.d/uruk force-reload, your box is open during a short while. If you don't like this, read below about uruk-save.

  THE GORY DETAILS: uruk INTERNALS
      The uruk script works like (and looks like) the list of statements below. Of course, take a look at /usr/sbin/uruk for the final word on the
      workings.

      1
	rc is sourced as a shell script
      2
	Traffic on $interfaces_unprotect (just lo per default) is trusted:

	 $iptables -A INPUT -i $iface -j ACCEPT

      3
	$rc_a is sourced as a shell script, or, in case $rc_a is a directory, all files matching $rc_a/*.rc are sourced as shell scripts
      4
	ESTABLISHED and RELATED packets are ACCEPT-ed:

	 $iptables -A INPUT -m state --state ESTABLISHED,RELATED 
	  -j ACCEPT

      5
	$rc_b is sourced
      6
	$interfaces  gets protected against spoofing: we don't allow anyone to spoof non-routeable addresses. We block outgoing packets that don't
	have our address as source: they are either spoofed or something is misconfigured (NAT disabled, for instance). We want  to  be  nice  and
	don't send out garbage.

	 $iptables -A INPUT -i $iface --source $no_route_ip 
	  -j DROP

	We drop all incoming packets which don't have us as destination:

	 $iptables -A OUTPUT -o $iface --source ! "$ip" 
	  -j DROP

	And we always allow outgoing connections:

	 $iptables -A OUTPUT -m state --state NEW -o $iface 
	  -j ACCEPT

      7
	$rc_c is sourced
      8
	Allow traffic to offered services, from trusted sources:

	 $iptables -A INPUT -m state --state NEW 
	  -i $iface --protocol $proto --source "$source" 
	  --destination "$ip" --destination-port "$port" 
	  -j ACCEPT

      9
	$rc_d is sourced
      10
	Don't answer broadcast and multicast packets:

	 $iptables -A INPUT -i $iface --destination "$bcast" 
	  -j DROP

      11
	$rc_f is sourced
      12
	Explicitly allow a subset of the ICMP types. (We disallow all other traffic later.)

	 $iptables -A INPUT --protocol icmp --icmp-type $type 
	  -j ACCEPT

      13
	$rc_g is sourced
      14
	Log packets (which make it till here)

	 $iptables -A INPUT -j LOG --log-level debug 
	  --log-prefix 'iptables: '

      15
	$rc_h is sourced
      16
	Reject all other packets

	 $iptables -A INPUT -j REJECT

      17
	$rc_i is sourced

  USING uruk-save AS THE INITSCRIPT BACKEND
      By  default,  uruk-save is not used by the uruk init script. You might want to use it, though. The uruk-save script is faster and when using
      uruk-save, your box won't be open while loading new rules. But beware: uruk-save is not as robust as using  uruk	itself.  However,  if  you
      don't use any hooks in your rc file, you're save.

      The init script will use uruk-save only if asked to do so in /etc/default/uruk (or /etc/sysconfig/uruk). If this file features

       enable_uruk_save=true
       enable_uruk_save_warning=false

      uruk-save is used whenever appropriate. The enable_uruk_save_warning variable controls whether a warning should get displayed whenever uruk-
      save is called.  See uruk-save(8) for more details.

  DEFAULT POLICY
      By default, uruk drops packets which have unknown RFC 1918 private network addresses in their source or destination.

      It rejects packets with source nor destination for one of our IPs.

      Packets belonging to locally initiated sessions are allowed: we match state; the local host can act as a client for any remote service.

      By default, uruk drops all ICMP packets (except those for interfaces in $interfaces_unprotect) with type other than

      o
	address-mask-reply
      o
	address-mask-request
      o
	destination-unreachable (this is a catch-all for a lot of types)
      o
	echo-request
      o
	echo-reply
      o
	parameter-problem (catch-all for ip-header-bad and required-option-missing)
      o
	timestamp-reply
      o
	timestamp-request
      o
	ttl-zero-during-transit
      o
	ttl-zero-during-reassembly

      By default, the FORWARD chain is left untouched, so has policy ACCEPT. (This won't do much harm, since  packet  forwarding  is  disabled	by
      default in the Linux kernel. However, if you don't mind being paranoid, you might want to add a

       iptables --policy FORWARD REJECT

      to your $rc_a uruk hook. See uruk-rc(5).)

      By  default,  uruk logs all UDP and TCP packets which are blocked by the user defined policies. Loglevel is debug, logprefix is "iptables:".
      See also the notes on loglevel in uruk-rc(5).

      Blocked TCP packets are answered with a tcp-reset.

  WARNING
      In order to keep the uruk script small and simple, the script does very little error handling. It does not check the contents of the rc file
      in any way before executing it. When your rc file contains bogus stuff, uruk will very likely behave in unexpected ways. Caveat emptor.

  ENVIRONMENT
      You can override some defaults in the shell before executing the uruk script.  uruk honors the following variables:

      o
	"URUK_CONFIG" Full pathname of rc file; /etc/uruk/rc by default.
      o
	"URUK_IPTABLES" Full pathname of iptables executable.  /sbin/iptables by default. Overrides iptables.
      o
	"URUK_IP6TABLES" Full pathname of ip6tables executable, for IPv6 support. Overrides ip6tables.
      o
	"URUK_INTERFACES_UNPROTECT" Default list of unprotected interfaces.  Overrides interfaces_unprotect. The default default is lo.

  SEE ALSO
      uruk-rc(5), uruk-save(8). The Uruk homepage is at http://mdcc.cx/uruk/ .

      iptables(8), iptables-save(8), iptables-restore(8), ip6tables(8), ip6tables-save(8), ip6tables-restore(8), http://www.netfilter.org/

      interfaces(5), http://packages.debian.org/ifupdown.

  COPYRIGHT
      Copyright  (C)  2003 Stichting LogReport Foundation logreport@logreport.org; Copyright (C) 2003, 2004 Tilburg University http://www.uvt.nl/;
      Copyright (C) 2003, 2004, 2005, 2010 Joost van Baal <joostvb-uruk@mdcc.cx>

      This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License  as  published	by
      the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL-
      ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

      You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

  AUTHOR
      Joost van Baal <joostvb-uruk@mdcc.cx>

  uruk 20120530 						      30 mai 2012							     uruk(8)
All times are GMT -4. The time now is 02:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy