Difference between revisions of "Cluster der kan alt/Routning og NAT"

From Teknologisk videncenter
Jump to: navigation, search
m
m (Routning & NAT)
Line 2: Line 2:
 
Configuring NAT (Sharing Internet)
 
Configuring NAT (Sharing Internet)
  
 +
==Start Routing==
 
For this, we do not need to install anything new. Everything is right there but is currently disabled. First, edit /etc/sysctl.conf. Find this:
 
For this, we do not need to install anything new. Everything is right there but is currently disabled. First, edit /etc/sysctl.conf. Find this:
#net.ipv4.ip_forward=1
+
<source lang=cli>
 +
net.ipv4.ip_forward=1
 +
</source>
 
Uncomment it by removing the #. Now forwarding is enabled in the system kernel.
 
Uncomment it by removing the #. Now forwarding is enabled in the system kernel.
Now write:
+
===Start routing without a reboot===
 +
<source lang=cli>
 +
echo 1 > /proc/sys/net/ipv4/ip_forward
 +
</source>
 +
This will enable it without a reboot.
 +
==NAT==
 +
<source lang=cli>
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
 +
</source>
 
What this does is make a NAT rule for post-routing. It sets the eth0 as the output card (The one out to the internet) and sets source to it's own IP through MASQUERADE. Then write:
 
What this does is make a NAT rule for post-routing. It sets the eth0 as the output card (The one out to the internet) and sets source to it's own IP through MASQUERADE. Then write:
echo 1 > /proc/sys/net/ipv4/ip_forward
 
This will enable it without a reboot.
 
 
Just to be sure, save it.
 
Just to be sure, save it.
 +
<source lang=cli>
 
iptables-save > /etc/iptables.rules
 
iptables-save > /etc/iptables.rules
 +
</source>
 
Now that it’s saved we need to load the iptables.rules on starting the network:
 
Now that it’s saved we need to load the iptables.rules on starting the network:
 +
 
vi /etc/network/interfaces  
 
vi /etc/network/interfaces  
 +
</source lang=cli>
 
# The extended interfaces
 
# The extended interfaces
 
auto eth0
 
auto eth0
Line 19: Line 31:
 
pre-up iptables-restore < /etc/iptables.rules
 
pre-up iptables-restore < /etc/iptables.rules
 
post-down iptables-restore < /etc/iptables.rules
 
post-down iptables-restore < /etc/iptables.rules
 +
</source>
 
Test it out on your other client.
 
Test it out on your other client.
 +
{{Source cli}}
 +
[[Categori:cluster]][[Categori:Ubuntu]]

Revision as of 13:29, 18 April 2012

Routning & NAT

Configuring NAT (Sharing Internet)

Start Routing

For this, we do not need to install anything new. Everything is right there but is currently disabled. First, edit /etc/sysctl.conf. Find this:

net.ipv4.ip_forward=1

Uncomment it by removing the #. Now forwarding is enabled in the system kernel.

Start routing without a reboot

echo 1 > /proc/sys/net/ipv4/ip_forward

This will enable it without a reboot.

NAT

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

What this does is make a NAT rule for post-routing. It sets the eth0 as the output card (The one out to the internet) and sets source to it's own IP through MASQUERADE. Then write: Just to be sure, save it.

iptables-save > /etc/iptables.rules

Now that it’s saved we need to load the iptables.rules on starting the network:

vi /etc/network/interfaces </source lang=cli>

  1. The extended interfaces

auto eth0 iface eth0 inet dhcp pre-up iptables-restore < /etc/iptables.rules post-down iptables-restore < /etc/iptables.rules </source> Test it out on your other client.

Categori:clusterCategori:Ubuntu