# Can the tap0 has a IP?

## wmaple

Hi,

I want to run qemu with network support, but the the host and the guest can not ping each other.

My bridger's configuration is as follows:

bridge_br0="eth0"

config_eth0=( "null" )

config_br0=( "dhcp" )

dhcpcd_br0="-t 10"

RC_NEED_br0="net.eth0"

brctl_br0=( "setfd 0" "sethello 1" "stp off" )

and all work well.

Then, I tried to config the 'tap0'

1. tunctl -t tap0 -u root

2. ifconfig tap0 0.0.0.0 promisc up

3. brctl addif tap0

Fininally, the qemu was started with:

qemu -kernel ... -net nic -net tap0,script=no -vnc :1

The guest's IP is configed and the IP is in the same subnet with the host.  In both the host and the guest, the IP forward is opened.

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

But, the host and the guest can not ping each other.

I checked the bridger's state:

brctl show stp br0

and got these messags:

... ... ...

tap0 (2)

 port id                     8002                    state                  disabled designated root        8000.000c298019ee       path cost                100

 designated bridge      8000.000c298019ee       message age timer          0.00

 designated port        8002                    forward delay timer        0.00

 designated cost           0                    hold timer                 0.00

 flags

I found the tap0 is disabled. So, I wonder whether or not the tap0 should has an IP. Then, I gave it an IP:

ifconfig tap0 192.168.0.5 up

Then, I found my ssh session is broken and can not ping the host from another workstation. At the console, showed the br0's state again, and the tap0 was still disabled.

ifconfig tap0 down

I got back.

It seems that the 'tap0' can not has an IP. But, if so, the 'tap0' port is disabled. I have no idea how to deal with the problem. 

... ... ...

----------

## wmaple

In fact, whether or not the 'tap0' has an IP does not matter. Then, how to enable the tap0? thx.

----------

## Hu

You are still using the legacy baselayout-1 style network configuration.  You should convert to openrc-style for your /etc/conf.d/net.  The syntax is close enough that it should still work for now, though.

What is the output of brctl show; /sbin/ip a; /sbin/ip r on the host and /sbin/ip a; /sbin/ip r in the guest?  What IP did the guest try to ping?

----------

## wmaple

The output of 'brctl show':

```

bridge name     bridge id                     STP enabled     interfaces

br0             8000.000c298019ee          no                   eth0

                                                        tap0 

```

----------

## wmaple

I do not have ip command. The output of ifconfig in host:

```

br0       Link encap:Ethernet  HWaddr 00:0c:29:80:19:ee

          inet addr:192.168.6.20  Bcast:192.168.6.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe80:19ee/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:1176 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1238 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:70888 (69.2 KiB)  TX bytes:573377 (559.9 KiB)

eth0      Link encap:Ethernet  HWaddr 00:0c:29:80:19:ee

          inet6 addr: fe80::20c:29ff:fe80:19ee/64 Scope:Link

          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:3367 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1649 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:724105 (707.1 KiB)  TX bytes:594903 (580.9 KiB)

          Interrupt:19 Base address:0x2000

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:4 errors:0 dropped:0 overruns:0 frame:0

          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:448 (448.0 B)  TX bytes:448 (448.0 B)

tap0      Link encap:Ethernet  HWaddr 22:3f:45:5a:b3:20

          UP BROADCAST PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:500

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

```

----------

## wmaple

The output of ifconfig in the guest:

```

eth0   Link encap:Ethernet HWaddr 52:54:00:12:34:56

   inet addr:192.168.6.4  Bcast:192.168.6.255  Mask: 255.255.255.0

   inet6 addr:  fe80:5054:ff:fe12:3456/64 Scope:Link

   ... ... ...

```

Sorry, I can not capture my screen output. So, copy the above messages by part.

----------

## wmaple

The output of brctl showstp br0:

```

br0

 bridge id              8000.000c298019ee

 designated root        8000.000c298019ee

 root port                 0                    path cost                  0

 max age                  19.99                 bridge max age            19.99

 hello time                0.99                 bridge hello time          0.99

 forward delay             0.00                 bridge forward delay       0.00

 ageing time             299.95

 hello timer               0.74                 tcn timer                  0.00

 topology change timer     0.00                 gc timer                  29.87

 flags

eth0 (1)

 port id                8001                    state                forwarding

 designated root        8000.000c298019ee       path cost                100

 designated bridge      8000.000c298019ee       message age timer          0.00

 designated port        8001                    forward delay timer        0.00

 designated cost           0                    hold timer                 0.72

 flags

tap0 (2)

 port id                8002                    state                  disabled

 designated root        8000.000c298019ee       path cost                100

 designated bridge      8000.000c298019ee       message age timer          0.00

 designated port        8002                    forward delay timer        0.00

 designated cost           0                    hold timer                 0.00

 flags

```

[/list]

----------

## wmaple

No reply?

I think the key point is at the 'tap0' can not be opened. But I don't know how to deal with it, I have checked the kernel configuration about 'TAP/TUN' and the ethernet's bridge support.

----------

## Hu

 *wmaple wrote:*   

> No reply?
> 
> I think the key point is at the 'tap0' can not be opened. But I don't know how to deal with it, I have checked the kernel configuration about 'TAP/TUN' and the ethernet's bridge support.

 I am still waiting for the rest of the output.  What do you mean the device cannot be opened?  None of your output shows that.

----------

## wmaple

```

tap0 (2) 

 port id                8002                    state                  disabled 

 designated root        8000.000c298019ee       path cost                100 

 designated bridge      8000.000c298019ee       message age timer          0.00 

 designated port        8002                    forward delay timer        0.00 

 designated cost           0                    hold timer                 0.00 

 flags 

```

I mean the state is 'disabled' rather than 'forwarding'. I have done the same configuration in ubuntu. When 'ifconfig tap0 0.0.0.0 up', the state is set with 'forwwarding'. But, in gentoo, this configuration can not achieve that.

----------

## salahx

There was change in 2.6.36 on how the tun/tap interface worked - previously they were always up as soon as created, but now "carrier" is enable only when something had file descriptor from the TUNSETIFF.

So the commandline for qemu need to be:

```
qemu -kernel -net tap,ifname=tap0,script=no ....
```

This will make qemu issue the TUNSETIFF to create the fd to enable the carrier.

By the way, you may want to install the iproute2 package, which contains the /sbin/ip tool, which can do a number of things - even create tun/tap interfaces as such (which interestingly enough isn't documented anywhere):

```
ip tuntap add dev tap0 mode tap
```

----------

## wmaple

Does not work. I post my operation:

```

ifconfig eth0 down

brctl addbr br0 

brctl addif br0 eth0

ifconfig br0 0.0.0.0 promisc up

ifconfig eth0 0.0.0.0 promisc up

dhchcd br0

qemu -kernel arch/x86/boot/bzImage -net nic -net tap,ifname=tap0,script=no

brctl addif br0 tap0

```

But. the tap0's state remains 'disabled'. The 'ip' command does not take effect also.

----------

## salahx

Don't put an IP address on eth0 if you're going to bridge it (same goes for the tap0). Also don't forget to up the tap0 interface

Now I tried it an it works (using iproute2 instead though):

```

ip tuntap add dev tap0 mode tap

ip set link eth0 down

brctl addbr br0

brctl addif br0 eth0

ip link set br0 up

ip link set eth0 up

ip link set tap0 up

dhcpcd br0

qemu -cdrom /var/lib/libvirt/images/Fedora-16-i386-DVD.iso -net nic -net tap,ifname=tap1,script=no,downscript=no

brctl addif br0 tap0

```

Then I run brctl showstp br0 and the output shows it working:

```

br0

 bridge id      8000.001a920b3470

 designated root   8000.001a920b3470

 root port         0         path cost         0

 max age        19.99         bridge max age        19.99

 hello time         1.99         bridge hello time      1.99

 forward delay        14.99         bridge forward delay     14.99

 ageing time       299.95

 hello timer         1.15         tcn timer         0.00

 topology change timer      0.00         gc timer       262.29

 flags         

eth0 (1)

 port id      8001         state           forwarding

 designated root   8000.001a920b3470   path cost        19

 designated bridge   8000.001a920b3470   message age timer      0.00

 designated port   8001         forward delay timer      0.00

 designated cost      0         hold timer         0.14

 flags         

tap0 (2)

 port id      8002         state           forwarding

 designated root   8000.001a920b3470   path cost       100

 designated bridge   8000.001a920b3470   message age timer      0.00

 designated port   8002         forward delay timer      0.00

 designated cost      0         hold timer         0.14

 flags         

```

----------

## wmaple

Yes, it really works. I have forgetton to bring the tap0 up. Thank you very much.

----------

