I am trying to enable AP and Wireless client on the Raspberry Pi 3 b+.
I have installed Raspbian Stretch from the official website.
To achieve the above objective I found an answer here which helped me in achieving this.
Configuration steps are as follows =>
rpi ~$ sudo -Es
rpi ~# apt-get update && apt-get upgrade
# Install hostapd
rpi ~# apt install hostapd
rpi ~# systemctl unmask hostapd
rpi ~# systemctl enable hostapd
# disable debian networking and dhcpcd
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# sudo mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf
# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
rpi ~# cat > /etc/hostapd/hostapd.conf <<EOF
interface=ap0
driver=nl80211
ssid=RPiNet
country_code=DE
hw_mode=g
channel=1
auth_algs=1
wpa=2
wpa_passphrase=verySecretPassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF
rpi ~# chmod 600 /etc/hostapd/hostapd.conf
rpi ~# sed -i 's/^#DAEMON_CONF=.*$/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/' /etc/default/hostapd
rpi ~# systemctl --full edit hostapd.service
I commented the After=network.target line =>
#After=network.target
rpi ~# systemctl edit hostapd.service
Add the content below for the above command =>
[Unit]
[email protected]
[Service]
ExecStartPre=/sbin/iw dev wlan0 interface add ap0 type __ap
ExecStopPost=-/sbin/iw dev ap0 del
After that, I did the setup of wpa_supplicant =>
rpi ~# cat >/etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="TestNet"
psk="realyNotMyPassword"
key_mgmt=WPA-PSK # see ref (4)
}
EOF
rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable [email protected]
Extend wpa_supplicant with:
rpi ~# systemctl edit [email protected]
Added the content below in [email protected] =>
[Unit]
BindsTo=hostapd.service
After=hostapd.service
[Service]
ExecStartPost=/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE
After this, I did the setup of static interface =>
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
IPForward=yes
# If you need a static ip address toggle commenting next three lines (example)
DHCP=yes
#Address=192.168.10.60/24
#Gateway=192.168.10.1
# Optional: if you want to connect to your own DNS server, set it here (example)
#DNS=192.168.10.10 8.8.8.8
EOF
rpi ~# cat > /etc/systemd/network/12-ap0.network <<EOF
[Match]
Name=ap0
[Network]
Address=192.168.4.1/24
DHCPServer=yes
[DHCPServer]
# If you want to connect to your own DNS server, set its ip address here
DNS=84.200.69.80 84.200.70.40
EOF
After this, I rebooted the Raspberry Pi
rpi ~# reboot
After this, when I checked the interfaces using ifconfig
command I found that the eth0
interface is missing.
ifconfig
output before the above configuration =>
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 2d43:8190:46bf:1:8df5:d1ad:9279:1424 prefixlen 64 scopeid 0x0<global>
inet6 ge81::ha25:48d3:ebcc:484a prefixlen 64 scopeid 0x20<link>
ether c8:23:fb:13:8f:g1 txqueuelen 1000 (Ethernet)
RX packets 266 bytes 34126 (33.3 KiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 106 bytes 15633 (15.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet <ip_address> netmask <ip_address>
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 172 bytes 14028 (13.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 172 bytes 14028 (13.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 fe70::aa27:ebfc:fg44:dbc4 prefixlen 64 scopeid 0x20<link>
ether c8:e7:e2:64:hb:b3 txqueuelen 1000 (Ethernet)
RX packets 163 bytes 17564 (17.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 105 bytes 16759 (16.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifconfig
output after the above configuration =>
ap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 ge90::aa27:ebhf:fe44:dcb4 prefixlen 64 scopeid 0x20<link>
ether 48:37:eb:54:ab:b3 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 5521 (5.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet <ip_address> netmask <ip_address>
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 172 bytes 14028 (13.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 172 bytes 14028 (13.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 fe70::aa27:ebfc:fg44:dbc4 prefixlen 64 scopeid 0x20<link>
ether c8:e7:e2:64:hb:b3 txqueuelen 1000 (Ethernet)
RX packets 163 bytes 17564 (17.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 105 bytes 16759 (16.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifconfig -a
output after the above configuration =>
ap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 ge90::aa27:ebhf:fe44:dcb4 prefixlen 64 scopeid 0x20<link>
ether 48:37:eb:54:ab:b3 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 5521 (5.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether c8:23:fb:13:8f:g1 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet <ip_address> netmask <ip_address>
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 172 bytes 14028 (13.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 172 bytes 14028 (13.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet <ip_address> netmask <ip_address> broadcast <ip_address>
inet6 fe70::aa27:ebfc:fg44:dbc4 prefixlen 64 scopeid 0x20<link>
ether c8:e7:e2:64:hb:b3 txqueuelen 1000 (Ethernet)
RX packets 163 bytes 17564 (17.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 105 bytes 16759 (16.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Note:
I have connected raspberry pi to the router using an ethernet connection. So it should get an IP address.
I get the same output as above for
ifconfig
command if I runifconfig eth0 up
command.
Question =>
I am not able to figure out or understand why ethernet configuration is getting disabled after doing the configuration steps I mentioned above.