titusece
Posts: 58
Joined: Sat Sep 10, 2016 3:24 pm
Location: India
Contact: Facebook Skype

Network : Setting static IP addresses for WLAN0 & ETH0 on raspberry pi3 board (latest stretch raspian image)

Wed May 23, 2018 4:52 pm

Hello Experts,
Want to assign static IP addresses for ethernet and wifi interfaces (eth0 & wlan0) for raspberry pi3 board.
And I have to try with latest stretch raspian lite version image.

I will do the below commands in script while creating SD card image file, so that every image has their own wifi network IP addresses.

Able to ping the both addresses if I connect the ethernet cable, btw, I also should use this method in raspberry pi zero board too (i.e only WLAN0)

sudo echo "auto eth0
iface eth0 inet static
address $ETH0_IP_ADDRESS
netmask $ETH0_NETMASK
gateway $ETH0_GATEWAY" >> $PWD/rootfs/etc/network/interfaces

sudo echo "allow-hotplug wlan0
iface wlan0 inet static
address $WLAN0_IP_ADDRESS
netmask $WLAN0_NETMASK
gateway $WLAN0_GATEWAY
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf" >> $PWD/rootfs/etc/network/interfaces

sudo echo -e "update_config=1
network={
ssid=\"$WIFI_SSID\"
psk=\"$WIFI_PASSWD\"
} " >> $PWD/rootfs/etc/wpa_supplicant/wpa_supplicant.conf

Can you please help me on this ?

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

Re: Network : Setting static IP addresses for WLAN0 & ETH0 on raspberry pi3 board (latest stretch raspian image)

Wed May 23, 2018 8:04 pm

Don't use /etc/network/interfaces to assign static net settings.
Use /etc/dhcpcd.conf. There are examples there to help you.

titusece
Posts: 58
Joined: Sat Sep 10, 2016 3:24 pm
Location: India
Contact: Facebook Skype

Re: Network : Setting static IP addresses for WLAN0 & ETH0 on raspberry pi3 board (latest stretch raspian image)

Fri May 25, 2018 4:10 pm

Thanks for the help.
Following command works.

Code: Select all

	sudo echo -e "interface eth0
		fallback static_eth0
		static ip_address=$ETH0_IP_ADDRESS/24
		static routers=$ETH0_GATEWAY
		static domain_name_servers=$ETH0_GATEWAY" >> $PWD/rootfs/etc/dhcpcd.conf

	sudo echo -e "interface wlan0
		static ip_address=$WLAN0_IP_ADDRESS/24
		static routers=$WLAN0_GATEWAY
		static domain_name_servers=$WLAN0_GATEWAY" >> $PWD/rootfs/etc/dhcpcd.conf

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 15 guests