o5i
Posts: 14
Joined: Sat Aug 06, 2016 6:38 pm

How to setup static eth0 and dhcp wlan0 on stretch?

Thu Oct 12, 2017 9:46 am

I have tried to setup the eth0 connection to a static ip using the dhcpcd.conf but it seems dhcpcd ignores the settings.

Code: Select all

# Static IP configuration for eth0.
interface eth0
static ip_address=192.168.1.1/24
I have tried changing the interfaces too but in that case i loose the wlan connection so i left how it was.

Code: Select all

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto eth0
allow-hotplug eth0
iface eth0 inet manual

Code: Select all

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:7a:02:7f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:2f:57:2a brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.13/24 brd 192.168.2.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::de6e:c202:6579:d8f1/64 scope link
       valid_lft forever preferred_lft forever
How to fix this?

SurferTim
Posts: 1010
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: How to setup static eth0 and dhcp wlan0 on stretch?

Thu Oct 12, 2017 10:23 am

This should be the only uncommented line in /etc/network/interfaces

Code: Select all

source-directory /etc/network/interfaces.d
Remove everything else, reboot and post the output of ifconfig.

Edit: This applies only to Stretch! Jessie has entries in /etc/network/interfaces.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: How to setup static eth0 and dhcp wlan0 on stretch?

Sun Oct 15, 2017 5:51 pm

Quite some people face the same problem that Stretch' dhcpcd does not handle fix ip well this days.

I have just built an Access Point (uap0, need fix ip itself) + wireless client (wlan0, get ip from router) on my zero w. As a temporary fix, I only put wlan0 in /etc/network/interfaces and have ip commands (i.e. ip link set dev uap0 up, ip addr add ...) in script that run by /etc/rc.local to setup fix ip for uap0.

Even though my AP is working properly (Android phone connect to it can get access to internet), I still get "failed" error when running systemctl status dhcpcd. I think it is a stretch's problem and have to wait till them to fix it.

SurferTim
Posts: 1010
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: How to setup static eth0 and dhcp wlan0 on stretch?

Sun Oct 15, 2017 6:37 pm

@coopi: Post a link to the setup you are using, or what you are trying. Normally dhcpcd service will fail if you put anything like "iface wlan0" in /etc/network/interfaces.

coopi
Posts: 18
Joined: Sun Apr 16, 2017 3:46 pm

Re: How to setup static eth0 and dhcp wlan0 on stretch?

Sun Oct 15, 2017 6:58 pm

SurferTim wrote:
Sun Oct 15, 2017 6:37 pm
@coopi: Post a link to the setup you are using, or what you are trying. Normally dhcpcd service will fail if you put anything like "iface wlan0" in /etc/network/interfaces.
Okay, just for reference cause it is not directly relevant to the topic I think.
I have

Code: Select all

auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
append to the default lines w/o comment out the interfaces.d one inside /etc/network/interfaces.

I have the fixed ip uap0 constructed in a script for my hostapd.conf. Only quote some relevant lines below

Code: Select all

iw dev wlan0 interface add uap0 type __ap
ip link set dev uap0 up
ip addr add 192.168.50.1/24 broadcast 192.168.50.255 dev uap0
And, yes, dhcpcd.service is reported failed. But my wlan0 does receive ip assinged to it.

SurferTim
Posts: 1010
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: How to setup static eth0 and dhcp wlan0 on stretch?

Sun Oct 15, 2017 9:23 pm

This is for an AP and client on the same wireless interface. I think I have everything here. I'm still testing it.
This is for Stretch ONLY!
DO NOT MODIFY /etc/network/interfaces FILE! The only uncommented line in that file should be
source-directory /etc/network/interfaces.d

First, insure your OS is up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Open /etc/wpa_supplicant/wpa_supplicant.conf with a text editor.
Save as /etc/wpa_supplicant/wpa_supplicant-wlan0.conf.
Add this to wpa_supplicant-wlan0.conf

Code: Select all

network={
   ssid="MySSID"
   psk="MyPassphrase"
}
There should be no network entries in wpa_supplicant.conf!

Then install the modules.

Code: Select all

sudo apt-get install dnsmasq hostapd
Edit /etc/rc.local and add this above "exit 0". Note that is two underscores.

Code: Select all

iw dev wlan0 interface add uap0 type __ap
The /etc/dhcpcd.conf addition:

Code: Select all

interface uap0
static ip_address=192.168.4.1/24
The /etc/dnsmasq.conf file. This is all that should be in this file.

Code: Select all

interface=uap0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,12h
The /etc/hostapd/hostapd.conf file. Change the ssid and wpa_passphrase.

Code: Select all

interface=uap0
driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1
My iptables rule.

Code: Select all

sudo iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE
Then make the iptables rule permanent.

Code: Select all

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Then in /etc/rc.local, add this below the iw line:

Code: Select all

iptables-restore < /etc/iptables.ipv4.nat
reboot

Edit: You may need to reboot twice. The first reboot may not bring up wlan0 connected, but the second reboot should.

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 16 guests