Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Hello friends i am struck in routing traffic from the office to internet i have a network structure like this http://asthana.me/images/ip.png I have assigned static ip to the cent os server(which have two NIC) internal network in working fine, from my cent os i can browse the internet, but within the internal network which is after switch, i am unable to browse the internet i am using the iptable to resolve these issue from what i have found on internet i have tried following code but there are errors

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A FORWARD -i eth0 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i eth2 -o eth0 -j ACCEPT
-t nat -A POSTROUTING -o eth2 -j MASQUERADE
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

Whenever i try to restart the iptable i get the error in the following line

"    -t nat -A POSTROUTING -o eth2 -j MASQUERADE"

I have tried various codes but none works, my main issue i want to run internet inside office and want to host a domain with this IP, but i am unbale to do so.

Any help is greatly appreciated, and thanks in anticipation

The output of ifconfig is as follows, and to tell you my eth1 card is there but is not working

[root@ZyXEL2 ~]# ifconfig
 eth0      Link encap:Ethernet  HWaddr 00:25:22:1C:89:2D  
      inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::225:22ff:fe1c:892d/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:42968 errors:0 dropped:0 overruns:0 frame:0
      TX packets:16281 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:26041912 (24.8 MiB)  TX bytes:1683535 (1.6 MiB)

eth1      Link encap:Ethernet  HWaddr 00:E0:1C:3C:5C:40  
      inet6 addr: fe80::2e0:1cff:fe3c:5c40/64 Scope:Link
      UP BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:478 dropped:0 overruns:0 frame:0
      TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:0 (0.0 b)  TX bytes:2652 (2.5 KiB)
      Interrupt:23 Base address:0x8c00 

eth2      Link encap:Ethernet  HWaddr 00:E0:4A:09:C6:AA  
      inet6 addr: fe80::2e0:4aff:fe09:c6aa/64 Scope:Link
      UP BROADCAST MULTICAST  MTU:1400  Metric:1
      RX packets:2007 errors:0 dropped:0 overruns:0 frame:0
      TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:176727 (172.5 KiB)  TX bytes:2498 (2.4 KiB)
      Interrupt:22 Base address:0x6800 

lo        Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:16436  Metric:1
      RX packets:312 errors:0 dropped:0 overruns:0 frame:0
      TX packets:312 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:28959 (28.2 KiB)  TX bytes:28959 (28.2 KiB)

[root@ZyXEL2 ~]# 

And when i try to restart the iptable following output comes

 service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: iptables-restore v1.4.7: Line 14 seems to have a   -t     table option.

Error occurred at line: 14
 Try `iptables-restore -h' or 'iptables-restore --help' for more information.
                                                       [FAILED]

[root@ZyXEL2 ~]#

share|improve this question
    
Can you post output of ifconfig? Probably just interface names if you have done copy paste. And also post actual error message. Does this Centos box have public IP? I see a router on the picture, so we cannot know actual network setup –  titus Apr 3 at 11:19
    
Thanks @titus, pasted the ifconfig out put the iptable start as follows service iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: iptables-restore v1.4.7: Line 14 seems to have a -t table option. Error occurred at line: 14 Try `iptables-restore -h' or 'iptables-restore --help' for more information [FAILED] [root@ZyXEL2 ~]# –  amitasthana Apr 3 at 11:54

1 Answer 1

Use iptables command to insert or add rules.

After achieving results, which you satisfied with, use iptables-save command - which will generate proper formatted output. In your current case you are missing part:

*nat
....
COMMIT

It must looks like that(with your rule):

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
   ......
COMMIT

*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth2 -j MASQUERADE
COMMIT

Try take look at that NAT guide , in sense using iptables and enabling forwarding must be ok for CentOS.

Also notice that office client must have route added, that points your CentOS (acting as router), so you may wish setup DHCP Server on CentOs to supply correct settings to user machines.

Also take look for tcpdump command - very handy to check traffic and determine : rules are working or not.

share|improve this answer
    
Thanks for this help, actully i am trying to run a web server and route the traffic with the help of single static IP, is it possible or not? –  amitasthana Apr 4 at 6:42
    
You wish to setup web server on your CentOS for your office clients - you have do that as any web server install guide says. Web server setup is not much affected by converting your CentOS install to linux router. Or you mean something different ? Try to describe your use case(what u wish to get as result) more detailed. –  MolbOrg Apr 4 at 7:24
    
As i told i am trying to run web server as well as use the centos as web server and i have pretty much achieved it, but now a new problem came as i restarted the system it is giving the error error :- Could not update ICEAuthority file /var/lib/gdm/.ICEauthority I have seen solutions on web, but my problem is neither mouse nor keybord works while this error so i am unable to do any changes. –  amitasthana Apr 5 at 13:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.