# No internet on host after creating a hotspot

## andros705

Well so I've made a bridge:

```

ip link add name br0 type bridge

ip link set br0 up

```

and made interface enp2s0 slave to it's master

```

ip link set enp2s0 master br0

```

then I've configured hostapd and run it.

I've got something like this: enp2s0 <=br0=> wlp3s0

Now, I can connect with my phone to the hotspot and access the internet and all the local machines and they can access my phone  :Razz: 

But I cannot access the internet from my laptop which is the hotspot (victim) in this situation.

```

default via 10.107.0.254 dev enp2s0  proto static  metric 100 

10.10.20.201 via 10.107.0.254 dev enp2s0  proto dhcp  metric 100 

10.107.0.0/24 dev enp2s0  proto kernel  scope link  src 10.107.0.74  metric 100 

169.254.0.0/16 dev enp2s0  proto kernel  scope link  src 169.254.78.140  metric 2 

```

The ip of the gateway is 10.107.0.254, seems correct.

But the src is 10.107.0.74 which is the ip of my laptop (hotspot, victim, localhost).

I guess I know where is the issue but I am not sure how to approach the problem.

I can't just do 

```
ip route add default via 10.107.0.254 dev br0
```

----------

## bbgermany

Hi,

Where is your IP address set? On br0 or on enp2s0?

It should be set on br0!

greets, bb

----------

## szatox

How do you configure your network? (What tools? What commands? What is in your configs?)

This bit belowe is - obviously - wrong. You seem to be aware of it, though the point still holds: you don't use a device enslaved by a bridge directly, you use the bridge instead.

```
default via 10.107.0.254 dev enp2s0  proto static  metric 100

10.10.20.201 via 10.107.0.254 dev enp2s0  proto dhcp  metric 100

10.107.0.0/24 dev enp2s0  proto kernel  scope link  src 10.107.0.74  metric 100

169.254.0.0/16 dev enp2s0  proto kernel  scope link  src 169.254.78.140  metric 2 
```

Now:

 *Quote:*   

> I can't just do
> 
> ```
> ip route add default via 10.107.0.254 dev br0
> ```
> ...

 

Why? Because there is a conflict with this line below, or is there some other reason?

```
default via 10.107.0.254 dev enp2s0  proto static  metric 100
```

 So, how 'bout dropping this route before adding a new one?

Also, is your wifi device actually attached to the bridge? Depending on your hardware, attaching wifi to a bridge works in more or less funny (or clunky) way. Does brctl show report it?

----------

## andros705

 *szatox wrote:*   

> Also, is your wifi device actually attached to the bridge? Depending on your hardware, attaching wifi to a bridge works in more or less funny (or clunky) way. Does brctl show report it?

 

Yes, hostapd automatically handles attaching wifi device to the bridge, I can't use brctl because I am not on systemd but ip link gives me:

```

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000

2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000

3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP mode DEFAULT group default qlen 1000

4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000

```

So if I understand correctly wlp3s0 and enp2s0 are both attached to the bridge (master br0).

When I try to route through br0, even after removing old default route it gives me:

```

# ip route add default via 10.107.0.254 dev br0

RTNETLINK answers: Network is unreachable

```

 *bbgermany wrote:*   

> Hi,
> 
> Where is your IP address set? On br0 or on enp2s0?
> 
> It should be set on br0!
> ...

 

How do I do it?

Is it #ip route default via ...?

Thanks

----------

## bbgermany

Hi,

"ip route" is the false command! you need to configure a bridge interface in /etc/conf/net. For example like this:

```

config_enp2s0="null"

bridge_forward_delay_br0=0

bridge_hello_time_br0=1000

bridge_stp_state_br0=1

bridge_br0="enp2s0"

config_br0="dhcp" # if you use dhcp in your network. if you use static ip, change to your ip/netmask"

# routes_br0="default via 10.107.0.254" # uncomment this line, if you use static ip

```

start your hostapd and you should be set.

greets, bb

----------

## Ant P.

Do you need a bridge at all? My hostapd setup works fine with just `sysctl net.ipv4.ip_forward=1`.

----------

## joanandk

 *andros705 wrote:*   

> I can't use brctl because I am not on systemd but ip link gives me

 

What has brctl do with "not on systemd"?

You are mixing up terms. 

a) br0 is a bridge

b) ethernet slave is used for bonding and creates a bond0.

Bonding is used for load balancing and/or bandwidth enhancement (so 2x 1Gbps links will give nearly 2Gbps). Bridge on the other hand gives no benefits other than having a software switch.

As others have said, you must assign IP and routes on the br0, not enp2s0. So literally you create a bridge with the two physical interfaces, let net.br0 assign ip to br0 and you are good to go.

----------

## andros705

 *bbgermany wrote:*   

> Hi,
> 
> "ip route" is the false command! you need to configure a bridge interface in /etc/conf/net. For example like this:
> 
> ```
> ...

 

Can you just explain how is ip route "the false command"?

 *joanandk wrote:*   

>  *andros705 wrote:*   I can't use brctl because I am not on systemd but ip link gives me 
> 
> What has brctl do with "not on systemd"?
> 
> You are mixing up terms. 
> ...

 

I am not sure if I follow, but I'll try tomorrow.

----------

## szatox

 *Quote:*   

> I can't use brctl because I am not on systemd but ip link gives me(...)

 Command name ending in "ctl" does not imply it's systemd.

Your ip link outpus looks reasonably though.

But you certainly have your IP assigned to physical interface rather than bridge.

Now, ip is not a "false command" by any means. It is in fact the very same thing that netifrc uses through its modules. You can use it directly if you like, but there are more convenient tools for handling both, persistent configuration (netifrc) and dynamic configuration (dhcpcd, wicd...). Since this is Gentoo, there are a lot of ways to do the same thing. Showing your configs is a good start to fixing mistakes. Say, with a fresh eye we can spot many mistakes instantaneously, but throwing clues before you show any background at all can only be based on out previous experience with most frequently asked questions (AKA what other people got wrong before).

 *Quote:*   

> b) ethernet slave is used for bonding and creates a bond0. 

 Joanandk, I suppose this was intended for me.

I do not consider bonding and bridging to be scenarios so different from each other to invent a new name for the latter. You have a virtual device that does some magic on top of a physical device and you're not supposed to use the physical device directly at the same time. You know what I mean, I know what I mean, and the details of that particular magic are not relevant to the case in hand.

----------

## bbgermany

"ip route" adds or show the routes for your networks. you need to add an ip to your bridge, if you have created one. you either configure your network in /etc/conf.d/net or set an ip address via "ip addr add".

oh and yeah, ipforwarding is needed as well, but since youre not able to connect to the internet from the hostapd enabled system, i think you will need to configure an ip.

you should post the output of "ifconfig -a" from the hostapd system here. then we will show you, where you may need to switch stuff to get it working.

greets, bb

----------

## andros705

I think you was right. I had dhcpcd running at boot and assigning ip address to enp2s0, then I just created the bridge and bound these without running dhcpcd on br0.

I've killed dhcpcd on enp2s0 and run it on br0, works like a charm!

Thanks!

----------

