8

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?

1
  • Are you trying to bridge eth0 and tap0 (have this machine act as if it were an Ethernet switch)? Commented Jan 25, 2018 at 17:37

1 Answer 1

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)

8
  • 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? Commented Jan 25, 2018 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. Commented Jan 25, 2018 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 ? Commented Jan 25, 2018 at 20:31
  • Did you try to bridge? tap0 should be reachable. Commented Jan 26, 2018 at 0:47
  • 3
    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 Commented Jan 26, 2018 at 10:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.