LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-12-2012, 06:31 AM   #1
alsharifhoussam
Member
 
Registered: Apr 2005
Distribution: Fedora 14
Posts: 109

Rep: Reputation: 15
portfowarding question


Hello,
I had a gateway linux, my other PC runs mailserver ,
at the local network, when I go to http://192.168.10.10 I get the login to webmail,
the gateway had public IP, I want users over Internet which go to http://PUBLICIP:3000 or any other port to be able to view this mail server.
Any help?
Thanks
 
Old 01-12-2012, 09:16 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Assuming you're using iptables then google for IPTABLES FORWARD
 
Old 01-12-2012, 11:08 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
you can use this script to do it all for you ,if your using iptables:

Quote:
#!/bin/bash

echo "Enter your internal connection name first followed by your external connection name e.g: eth1 eth0"

if [ $# != 2 ]
then

INTIF="#1"

EXTIF="#2"

else

echo You need to enter two names,your internal connection name eg(etho) first then your external connection eg(eth1)

fi

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc

echo " Enabling IP forwarding..."
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

echo " External interface: $EXTIF"
echo " External interface IP address is: $EXTIP"

echo " Loading proxy server rules..."
# Clearing any existing rules and setting default policy
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F

# FWD: Allow all connections OUT and only existing and related ones IN
iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

# Enabling SNAT (MASQUERADE) functionality on $EXTIF
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

if [ $? -eq 0 ]
then
echo " Proxy server rule loading complete"
fi

Last edited by cbtshare; 01-12-2012 at 07:09 PM.
 
1 members found this post helpful.
Old 01-12-2012, 12:11 PM   #4
MartinStrec
Member
 
Registered: Jan 2012
Location: Czech
Distribution: Fedora, RHEL, Ubuntu, Mint
Posts: 110

Rep: Reputation: 14
If you want to config the same as the script of user 'cbtshare' does.

Edit /etc/sysconfig/iptables
and /etc/sysconfig/ip6tables

If your IP tables have been generated, use system-config-firewall or other system rather then modify those files directly.
Also tools like system-config-firewall or system-config-firewall-tui have GUI or TUI interface to easy set up NAT.

also modify /etc/sysctl.conf
if ip_forwarding is not enable by default
net.ipv4.ip_forward = 1
...
 
Old 01-12-2012, 06:51 PM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
[QUOTE=MartinStrec;4572967]

Quote:
also modify /etc/sysctl.conf
if ip_forwarding is not enable by default
net.ipv4.ip_forward = 1
Ahhh, yea, I edited the script to input your comment, thanks for that


new script is below:
Quote:
#!/bin/bash

if [ "$#" -eq "2" ]
then

INTIF="$1"

EXTIF="$2"

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc

echo " Enabling IP forwarding..."
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
FWDIP=$(sed 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' < /etc/sysctl.conf>/tmp/show.txt)
cp -f /tmp/show.txt /etc/sysctl.conf
echo " External interface: $EXTIF"
echo " External interface IP address is: $EXTIP"

echo " Loading proxy server rules..."

# Clearing any existing rules and setting default policy
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F

# FWD: Allow all connections OUT and only existing and related ones IN
iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

# Enabling SNAT (MASQUERADE) functionality on $EXTIF
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

if [ $? -eq 0 ]
then
echo " Proxy server rule loading complete"
fi

else

echo "You need to enter two names,your internal connection name eg(etho) first, then your external connection eg(eth1), example ./scrptname eth0 eth1

fi

Thank you

Last edited by cbtshare; 01-12-2012 at 07:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
basic html question - download link to files on my webpage question Davno Linux - Server 5 12-25-2009 07:24 AM
linux distro question & mysql install question natalie.aloi Linux - Newbie 5 07-19-2009 08:28 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration