linux嵌入式动态和静态获取ip

有时候需要静态或者动态获取ip,如果是动态获取ip,首先需要一直udhcpc,这个可以参考网上,有很多介绍,这里主要记录一下文件系统中通过interfaces脚本,获取ip

1. 动态获取ip

vim   /etc/network/interfaces,  编辑以下内容

#The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp

  

2.静态获取

vim   /etc/network/interfaces,  编辑以下内容

auto eth0
iface eth0 inet static
address 192.168.2.10
gateway 192.168.2.1
netmask 255.255.255.0

  

也可以直接这样获取

ifconfig   eth0  192.168.2.100

原文地址:https://www.cnblogs.com/ChenChangXiong/p/12010650.html