Set static ip to ethernet in android

Viewed 14229

I have ethernet connected to my android board. I want to manually set IP from code. I was able to set IP address for WIFI. I have looked into following links for ethernet

Assign static IP to ethernet card from OTG So far I have not found how to set static IP to ethernet via android code.

3 Answers

You may need to create /data/misc/ethernet/ipconfig.txt file to configure static IP address.
As you successfully configured static IP address for WiFi already,
I think /data/misc/wifi/ipconfig.txt was also created and it will be valid for Ethernet config, too.
Please refer to following links for file path and data format.
EthernetConfigStore.java
IpConfigStore.java

The steps will vary with different versions of android.

Go to Settings, click on Connections then WiFi. Tap and hold on the network you wish to adjust and click Manage Network Settings.
Mark the Show Advanced Options check box.
Click on the bottom checkbox to show advanced options Under IP Settings, change it from DHCP to Static.
Change DHCP to Static When using static IP addresses on home and other private networks, they should be chosen from within the standard private IP address ranges listed: 10.0.0.0 through 10.255.255.255 172.16.0.0 through 172.31.255.255 192.168.0.0 through 192.168.255.255 Now enter the IP address. This step is specific to each network. Ex: 192.168.1.128 The Gateway should fill in automatically based on the IP address. If not, copy the IP address and replace the last number with a 1. (Based on previous example: 192.168.1.1) Tap Save and let the network reconnect.

If you intend to convert a wifi connection to ethernet or vice-versa check this.

Related