7

Basically I am trying to create a custom TCP Stack. As you might know I cant use eth0 because linux kernel TCP stack uses that, Due to that I need to create a tun/tap interface and use it for my Custom TCP Stack.

/etc/network/interfaces:

auto lo
iface lo inet loopback

allow-hotplug eth0
auto eth0
iface eth0 inet static
    address 192.168.1.152
    netmask 255.255.255.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-server 192.168.1.1

allow-hotplug tap0
auto tap0
iface tap0 inet manual
    pre-up ip tuntap add tap0 mode tap user root
    pre-up ip addr add 192.168.1.153/24 dev tap0
    up ip link set dev tap0 up
    post-up ip route del 192.168.1.0/24 dev tap0
    post-up ip route add 192.168.1.152/32 dev tap0
    post-down ip link del dev tap0

ifconfig

inet addr:192.168.1.152 bcast:192.168.1.255 netmask 255.255.255.0

lo:
    inet addr:127.0.0.1 mask 255.0.0.0

tap0:
    inet addr: 192.168.1.153 bcast:0.0.0.0 mask 255.255.255.0

with following config I can reach wan/lan using eth0 but I cant reach not even my gateway with tap0.

I would really appreciate if you could tell me what mistake am I making here?

Mr. Nobody
  • 71
  • 1
  • 1
  • 3

1 Answers1

9

I would just bridge the two, in which case there will be no need for an IP address on tap0, i.e.;

brctl addif br0 tap0
ip link set tap0 master br0

or if you don't already have bridge-utils installed, then:

ip tuntap add tap0 mode tap
ip link set dev tap0 up
ip link add br0 type bridge
ip link set tap0 master br0
ip link set eth0 master br0

(configure the master, br0, with the IP address, the slaves will share it)

Shōgun8
  • 695
  • 5
  • 16
  • well if I bridge the 2 interfaces. then If a LAN/WAN packet came I never be able to see in my tap0 interface, right? – Mr. Nobody Jan 25 '18 at 19:21
  • I am not sure how you are trying to capture packets, but perhaps it would work if you had something attached to tap0; a VM for instance. – Shōgun8 Jan 25 '18 at 20:09
  • All right did you read my question update, about why do I need a tap interface? so for that purpose am I gonna be able to use a bridged eth0 and tap0 interface ? – Mr. Nobody Jan 25 '18 at 20:31
  • Did you try to bridge? tap0 should be reachable. – Shōgun8 Jan 26 '18 at 00:47
  • 2
    yep I bridged it but If I do a `ping x.x.x.x -I tap0` it doesnt work, nor does eth0, just the bridge which is `br0` works – Mr. Nobody Jan 26 '18 at 10:01
  • Did you give tap0 an IP address on the same subnet as eth0? And if so are you trying to ping it from the server on which it is configured, or from another machine that is somewhere on the network? – Shōgun8 Jan 26 '18 at 15:29
  • After I do execute all your command, my ssh has shutdown, I can't talk to my AWS ec2 any more ... :( – Frank AK Nov 13 '19 at 03:21
  • You must have been connected to eth0. It goes without saying that you must be careful to not do the work on the interface to which you are connected. I would recommend being connected to a physical console or connect to eth1 before preforming the work on eth0. – Shōgun8 Nov 13 '19 at 17:19