Andries filmer

Feel free with Open Source Software

Andries Filmer - Internet professional sinds 1996.
Ik ben groot voorstander van Free- en Opensource Software (FOSS) en laat deze site jouw overtuigen waarom dit goed is.
Home Over deze website Kennisbank Ezelsoren Freelancer Online gereedschap

Networking on linux

Index
  1. netstat
  2. Network tools
  3. IP Tunelling
    1. Starting Configuration
    2. Tunnelling Objective
    3. Additional Routes
    4. Delete Tunnels
    5. Network Diagram
    6. Debian Configuration
  4. Redirect ip-address port
  5. Comments

Some notes for networking on GNU / linux

netstat

List internet services on a system
 netstat -tupl

List active connections to/from system

 netstat -tup

Network tools

 apt-get install ethtool net-tools

Output eth0 configuration options

 ethtool eth0

Same with MII View (or manipulate media-independent interface) status

 mii-tool eth0

Change the speed and duplex settings

Disable autonegotiation, and force the MII to either 100baseTx-FD, 100baseTx-HD, 10baseT-FD, or 10baseT-HD

 mii-tool -F 100baseTx-HD
 mii-tool -F 10baseT-HDSetup 

Negotiated speed with ethtool

 ethtool -s eth0 speed 100 duplex full
 ethtool -s eth0 speed 10 duplex half

IP Tunelling

We will do IPv4 tunneling using GRE. GRE is a tunneling protocol that was originally developed by Cisco, and it can do a few more things than IP-in-IP tunneling. For example, you can also transport multicast traffic and IPv6 through a GRE tunnel.

We are using Debian with linux kernel 2.4.26. In Linux, you'll need the ip_gre.o module.

Starting Configuration

We have 2 routers X and Y, and intermediate network C (or let's say, Internet).

router X

Router X is connected to the Internet on interface eth0 and network A on eth1.

 interface eth0 :: address 169.229.255.134 on the Internet (or network C)
 interface eth1 :: address 10.0.2.1, network 10.0.2.0/24 (network A)

router Y

Router Y is connected to the Internet on interface eth0, network B on eth1 and network C on eth2.

 interface eth0 :: address 207.241.237.37 on the Internet (or network C)
 interface eth1 :: address 10.0.3.1, network 10.0.3.0/24 (network B)
 interface eth2 :: address 10.0.4.1, network 10.0.4.0/24 (network C)

As far as network C is concerned, we assume that it will pass any packet sent from X to Y and vice versa. How and why, we do not care.

Tunnelling Objective

Create a tunnel between router X and Y, such that we can route traffic from network A (connected to X) to networks B and C (connected to Y). This tunnel will look just like a wire between the two routers with its own subnet (10.0.201.0/24)

Create Tunnels

On router X, commands are

 iptunnel add tunX mode gre remote 207.241.237.37  local 169.229.255.134 ttl 225
 ifconfig tunX 10.0.201.1/24
 ifconfig tunX up
 ifconfig tunX pointopoint 10.0.201.2
 ifconfig tunX multicast

  • Line 1, we added a tunnel device, and called it tunX. Furthermore we told it to use the GRE protocol (mode gre), that the remote address is 207.241.237.37 (the router Y at the other end), that our tunneling packets should originate from 169.229.255.134 (which allows your router to have several interfaces and choose which one to use for tunneling) and that the TTL field of the packet should be set to 255 (ttl 255).
  • Line 2 gives the newly born interface tunY the address 10.0.201.1.
  • Line 3 enables the device.
  • Line 4 is necessary to set the IP address of the peer. Need when using dynamic routing with RIP/OSPF with Zebra. Refer to Routing HOWTO for more details.
  • Line 5 is necessary to enable multicast - so that routing with Zebra works (they normally multicast routing updates).

One router Y, commands are

 iptunnel add tunY mode gre local 207.241.237.37 remote 169.229.255.134 ttl 225
 ifconfig tunY 10.0.201.2/24
 ifconfig tunY up
 ifconfig tunY pointopoint 10.0.201.1
 ifconfig tunY multicast

Tunnel X<->Y
Now we created a tunnel on the 10.0.201.0/24 network from router X to Y and vice versa.

 routerX ----------------tunnel-----------------routerY 
        10.0.201.1                   10.0.201.2
         (tunX)                      (tunY)

We can send packets on the 10.0.201.0/24 network from router X to Y and vice versa. So we can ping router X from Y on the tunnel interface.

 routerX# ping 10.0.201.2
 routerY# ping 10.0.201.1

Additional Routes

However, if we to send packets to network B or C from router X, we need to add routes so that traffic for these networks is sent on the tunnelling interface.

On router X:

 route add -net 10.0.3.1/24 gw 10.0.201.1 dev tunX
 route add -net 10.0.4.1/24 gw 10.0.201.1 dev tunX

Similarily, to send packets to network A from router Y, we need to add a route.

On router Y:

 route add -net 10.0.2.1/24 gw 10.0.201.2 dev tunY

Delete Tunnels

On router X:

 ifconfig tunX down
 iptunnel del tunX

Network Diagram

  (network A)   
  10.0.2.1, eth1
     |
  ___|_________
 |  Router X   |
 |_____________|
     | 169.229.255.134 (eth0)
     | (Internet or network C)
     |
     |
    | |  10.0.201.1 (tunX)
    | |
    | | 
    | |  (gre tunnel: 169.229.255.134 <-> 207.241.237.37)
    | |
    | |
    | |  10.0.201.2 (tunY)
     |
     | (Internet or network C)
     | 207.241.237.37 (eth0)
  ___|___________
 | Router Y      |
 |_______________|
    |           |
    |           |
 10.0.3.1      10.0.4.1 
 eth1          eth2
 (network B)   (network C)

Debian Configuration

router X: /etc/network/interfaces

 auto tun0
 iface tun0 inet static
       address 10.0.201.1
       netmask 255.255.255.0
       broadcast 10.0.201.255
       up ifconfig tun0 multicast
       pre-up iptunnel add tun0 mode gre remote 207.241.237.37 local 169.229.255.134 ttl 255
       pointopoint 10.0.201.2
       post-down iptunnel del tun0

router Y: /etc/network/interfaces

 auto tun0
 iface tun0 inet static
       address 10.0.201.2
       netmask 255.255.255.0
       broadcast 10.0.201.255
       up ifconfig tun0 multicast
       pre-up iptunnel add tun0 mode gre local 207.241.237.37 remote 169.229.255.134 ttl 255
       pointopoint 10.0.201.1
       post-down iptunnel del tun0

Reference: http://tier.cs.berkeley.edu/wiki/HOWTO:IPTunnelling

Redirect ip-address port

Redirect ip-address port to other server port

/usr/local/bin/redir --laddr 82.201.122.21 --lport 80 --caddr 194.242.19.13 --cport 80

This page is created on 2009-11-24 and updated on 2010-03-30

I appreciate if you give some comment about this page. Please go ahead.
Your e-mailaddress will not be published it is only to contact you (if needed).

 
Your name
Your e-mailaddress
To prefent robots to use this form I ask you kindly to type the next characters in the input field.
 

 


Mijn Curriculum vitae | De content op deze website heeft de Creativecommons 3.0 licentie | © 2011
Andries Filmer | http://andries.filmer.nl | andries@filmer.nl | © 2011
Deze website wordt gerealiseerd met Free- en Open Source Software: | | | | | |