DNS and DHCP
Configuration Instruction
1. Configure Ethernet Dynamic IP¶
The SDK package we released compiles the image upgrade package and packs the udhcpc tool by default, which is used to dynamically obtain IP. You can use the following method to dynamically obtain the IP address for the specified network card. For example, for the eth0 network card, use the network cable to connect the board to the router (or other DHCP server) and then use the following command to dynamically obtain the IP
ifconfig eth0 up;
udhcpc -i eth0 -s /etc/init.d/udhcpc.script
2. Enable DNS¶
DNS depends on libresolv, libnsl, and libnxx_* series library files, which are not packaged into the upgrade image by default. They can be obtained from our supporting cross-compilation toolchain when needed. For example, in the cross-compilation toolchain of gcc-10.2.1, the library files that dns depends on are located in gcc-10.2.1-20210303-sigmastar-glibc-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/lib/, as follows:

You can package these lib libraries into the image together, or put them in the mount directory and add them to the LD_LIBRARY_PATH environment variable for testing, such as putting the above libraries in the /customer/dns directory and then export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/customer/dns
3. Add the default DNS name server¶
Normally, when DHCP obtains an IP address, the DHCP server will distribute a DNS server address. If the user needs to add a default server, follow the steps below:
Found in project\image\etc\init.d\udhcpc.script:
for i in &dns ;do echo "Adding DNS server $i" echo "nameserver $i" >> "$tmpfile" done
Modify or add at the end:
echo "name server 202.96.134.133" >> "$tmpfile"
4. Test the network¶
You can use the ping command to check whether the DNS configuration is normal. When the network communication is normal
ping www.baidu.com
PING www.baidu.com (163.177.151.109): 56 data bytes
64 bytes from 163.177.151.109: seq=0 ttl=128 time=54.557 ms
64 bytes from 163.177.151.109: seq=1 ttl=128 time=14.317 ms
64 bytes from 163.177.151.109: seq=2 ttl=128 time=4.245 ms
64 bytes from 163.177.151.109: seq=3 ttl=128 time=4.082 ms
If a log similar to the following appears, the IP address corresponding to the domain name can be obtained but the ping fails. This means that the domain name resolution is successful and the DNS works normally, but the development board cannot communicate normally with the target address. Please check the network environment settings to ensure that the network communication is normal.
ping -I eth0 www.baidu.com PING www.baidu.com (14.215.177.38):56 data bytes # This situation indicates that the DNS has been resolved to the IP, but the network restrictions prevent access to the external network.