Use DHCP in an embedded Linux system to automatically assign IP addresses to the Development Board

Source: Internet
Author: User

1. Check that DHCP is selected when the Linux kernel compilation is generated.

Networking --->
Networking Support
Networking options --->
PACKET socket // Add. Configure config_packet
[*] IP: DHCP support // Add
[*] Network packet filtering (replaces ipchains) ---> // Add the file. If this option is left blank, configure config_netfilter.

NOTE: If PACKET socket is not selected, the following error occurs when running the udhcpc command: [*] network packet filtering (replaces ipchains) --->:
~ # Udhcpc
Udhcpc (v0.9.9-pre) started
Udhcpc [208]: udhcpc (v0.9.9-pre) started
Fatal: Couldn't listen on socket, address family not supported by Protocol
Udhcpc [208]: Fatal: Couldn't listen on socket, address family not supported by Protocol

2. Compile busybox to make menuconfig and add the following options:

Networking utilities --->
Udhcp server/client --->
[] Udhcp server (udhcpd) // This is not used as the server, so it is not selected. Generate udhcpd command
Udhcp client (udhcpc) // generate udhcpc command
[] Lease display utility (dumpleases)
[] Log udhcp messages to syslog (instead of stdout)
[] Compile udhcp with noisy debugging messages
If busybox does not compile the corresponding options, you can also download the corresponding files from the Internet, use arm-Linux cross-compilation to get udhcpd, udhcpc command copy to usr/sbin.

Note: The udhcp_0.9.8cvs20050303.orig.tar.gz file on the internet is recommended. decompress the file and modify the makefile,
Add cross_compile = arm-Linux-
Comment out 12 rows of combined_binary = 1,
Otherwise, the udhcpc command is not generated.

Note: udhcp of version 0.9.8 does not seem to work either. recompile busybox1.9.2.

3. Use simple in busybox. script,/usr/share/udhcpc/, and rename it to default. script, modify default. resolv_conf = "/etc/resolv. conf "is resolv_conf ="/tmp/resolv. conf"

Note: It seems that the following default. script files cannot be found on the Internet. The above method is better. Because the cramfs file system is used, the etc directory cannot be written. When udhcp. C is run, a message is displayed, indicating that resolv. conf cannot be created.

4. Copy the generated udhcpc to the development board/sbin and run udhcpc on the console. You can quickly obtain the IP address from the DHCP server. However, if there is a problem, the Development Board can obtain the IP address, and you can also see the allocated address in the vro. The problem is that you can use the ping command to ping the Development Board or the Development Board to ping the PC, the Development Board will crash. I tried many methods, checked Route, checked ARP, and modified default. script.
.

It took a whole day to complete the solution.

1. First, I suspected the problem of busybox. OK. On the Development Board, I transplanted version 1.9.2. I found the latest version 1.14.0 on the Internet. For more information about porting, see another article.

2. busybox1.9.2 seems to be faulty. After udhcpc, you can view IP information through ifconfig to see that the broadcast address bcast is faulty. It is always 255.255.255.255. The correct value should be 192.168.1.255 (network segment: 192.168.1 ), if you use busybox1.14.0, the problem is that ping is still unavailable.

3. Disable the NIC after the udhcpc is detected by accident, and then restart the NIC to use the command

Ifconfig eth0 down
Ifconfig eht0 up

Then it will work normally. The problem is that you cannot ping the local machine. You can set the loopback address.

Ifconfig lo 127.0.0.1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.