ARM开发板修改设置静态IP

2019-07-12 23:23发布

微博搜索 bindingly   欢迎关注 所用IPdhcp服务器自动分配的IP地址,每次要使用开发板的IP都很麻烦,更麻烦的是每次还要在代码里改IP。要是有个路由器也好解决,给这个端口固定一个IP地址,而我恰恰是用的交换机还是没办法配置的那种交换机。那就只能通过命令行改IP地址。 一般有两改法: 一、直接配置网口IP地址和掩码 ifconfig eth0 10.150.11.2 netmask 255.254.0.0 在使用命令source命令进行同步,再通过ifconfig 查看IP地址,此时地址改成功了。但这种改法也是很麻烦的,每次重启、开机后都得改。 解释下source  linuxman source 得到如下解释: source filename [arguments] Read  and execute commands from filename in the current shell environment and return the exit status ofthe last command executed from filename.  If filename does not contain a slash, filenames in  PATH  areused  to find the directory containing filename.  The file searched for in PATH need not be executable. When bash is not in posix mode, the current directory is searched if no file is found in PATH.  If  thesourcepath  option  to the shopt builtin command is turned off, the PATH is not searched.  If any arguments are supplied, they become the positional parameters when filename  is  executed.   Otherwise  the positional parameters are unchanged.  The return status is the status of the last command exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read.  说白了就是:在当前bash环境下读取并执行FileName中的命令。该命令通常用命令“.”来替代。对你修改的文件进行同步,省去了重启开发板的操作。) 二、修改相应的shell程序 开发板一启动就给分配了IP地址,说明它是自启动的,那就肯定可以自启动的shell程序etc/initd/rcS中找到相应的信息,果不其然, /sbin/ifconfig lo 127.0.0.1               /etc/init.d/ifconfig-eth0   fa-network-service   现在就是顺着找ifconfig-eth0 ,查看该文件得到如下信息, #!/bin/sh echo -n Try to bring eth0 interface up......>/dev/ttySAC0 if [ -f /etc/eth0-setting ] ; then source /etc/eth0-setting if grep -q " / nfs " /etc/mtab ; then echo -n NFS root ... > /dev/ttySAC0 else DEV_ADDR=`cat /sys/class/net/eth0/address` if [ "$DEV_ADDR" = "00:00:00:00:00:00" ]; then ifconfig eth0 down ifconfig eth0 hw ether $MAC fi ifconfig eth0 $IP netmask $Mask up route add default gw $Gateway fi echo nameserver $DNS > /etc/resolv.conf
该文件肯定和/etc/eth0-setting有关,再顺着找到这个文件,发现就是在这里改,该文件如下: IP=10.150.11.2 Mask=255.254.0.0 Gateway=10.150.1.1 DNS=10.150.1.1 MAC=08:90:90:90:90:90 在这里根据你的需要去改,MAC地址最好不要去改,别的随便改,注意:=两边不能有空格,要是空格就修改不成功或出现如下错误,大家写习惯代码总喜欢两边空格。 Try to bring eth0 interface up....../etc/init.d/ifconfig-eth0: /etc/eth0-setting: line 1: IP: not found /etc/init.d/ifconfig-eth0: /etc/eth0-setting: line 2: Mask: not found /etc/init.d/ifconfig-eth0: /etc/eth0-setting: line 3: Gateway: not found /etc/init.d/ifconfig-eth0: /etc/eth0-setting: line 4: DNS: not found ifconfig: bad address 'up' 可是重启的时候发现还是会自动获取IP地址,那就肯定和DHCP有关,在etc/下有个DHCPD的文件卷,我直接简单粗暴的把那里面的一个可执行文件直接用命令chmod 000 dhcpcd-run-hooks,当然你也可以直接备份再删除。等你要用的时候再把权限改过来就好。 到此修改结束。