目录

1 成功的方法

1.1 临时设置ip地址(重启开发板失效)

1.2 永久设置ip地址

2 失败的方法

2.1 临时设置ip地址--失败的方法

2.2 永久设置ip地址--失败的方法

2.3 永久设置ip地址--失败的方法


这里以瑞芯微的RV1126开发板为例。

1 成功的方法

1.1 临时设置ip地址(重启开发板失效)

ifconfig eth0 172.31.8.xxx netmask 255.255.255.0
route add default gw 172.31.8.254

1.2 永久设置ip地址

vi /etc/profile,然后把前面临时配置ip地址的两行命令写到里面。

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

if [ "$PS1" ]; then
        if [ "`id -u`" -eq 0 ]; then
                export PS1='[\u@\h:\w]# '
        else
                export PS1='[\u@\h:\w]$ '
        fi
fi

export PAGER='/bin/more '
export EDITOR='/bin/vi'

# Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh ; do
        if [ -r "$i" ]; then
                . $i
        fi
        unset i
done

ifconfig eth0 172.31.8.xx netmask 255.255.255.0
route add default gw 172.31.8.254

2 失败的方法

2.1 临时设置ip地址--失败的方法

介绍下基本情况,我的windows电脑网段是172.31.8.x。然后ubuntu服务器地址是192.168.1.x。然后我的windows是可以ping通ubuntu服务器的。但是,我的开发板设置的网段是172.31.8.x。然后开发板ping不通ubuntu服务器,是因为我最开始设置开发板网址用的命令是

ifconfig eth0 172.31.8.xx netmask 255.255.255.0
route add default gw 172.31.8.1

然后我就看了下我的windows电脑的网址

 然后我就把我开发板的gw改成和我的wondows电脑一样的172.31.8.254,然后开发板就可以ping通ubuntu服务器了。

2.2 永久设置ip地址--失败的方法

vi /etc/init.d/rcS,然后把临时配置ip地址的命令写到里面,不生效。

#!/bin/sh


# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
ifconfig eth0 172.31.8.xx netmask 255.255.255.0
route add default gw 172.31.8.254
for i in /etc/init.d/S??* ;do

     # Ignore dangling symlinks (if any).
     [ ! -f "$i" ] && continue

     case "$i" in
        *.sh)
            # Source shell script for speed.
            (
                trap - INT QUIT TSTP
                set start
                . $i
            )
            ;;
        *)
            # No sh extension, so fork subprocess.
            $i start
            ;;
    esac
done

2.3 永久设置ip地址--失败的方法

vi /etc/network/interfaces,然后把临时配置ip地址的两行命令写到里面,不生效,失败。

# interface file auto-generated by buildroot

auto lo
#iface lo inet loopback

auto eth0
iface eth0 inet static
address 172.31.8.xx
gateway 172.31.8.254
netmask 255.255.255.0
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐