方法一
在Ubuntu2004(从机)打开一个终端,输入如下配置有线网络ip,其中eth0 为有线网络的名称,有时候名字可能叫enp1s0或者enp2s0,up的作用是使能有线网络eth0
sudo ifconfig eth0 192.169.10.2 up
方法二
点击ubuntu桌面右上方倒三角按钮-》点击wire Settings如下图所示:
点击如下红色框按钮设置有线ip
点击Mannual手动设置有线网ip,如下
并在.bashrc文件中输入如下内容,192.169.10.3为主机的ip,192.169.10.2为从机的ip
export ROS_MASTER_URI=http://192.169.10.3:11311
export ROS_HOSTNAME=192.169.10.2
查看有线网络的名称可以在终端输入ifconfig,如下
另一个Ubuntu系统(主机)打开终端输入
sudo ifconfig eth0 192.169.10.1 up
在主机的/data/local/setting下touch network,输入2,选择有线连接
主机开机自启动的业务脚本中加入如下内容,该内容会读取network中的内容,选择网络ip,并配置主机的主机的ip:
#!/bin/bash
sudo ifconfig eth0 192.169.10.1 up
version_path=/data/local/setting/network
if [ -f $version_path ]
then
version=$(cat $version_path)
echo $version
if [ $version = 1 ]
then
echo "is 164.178"
ip="$(ifconfig | grep -A 1 'wlan0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
elif [ $version = 2 ]
then
echo "is 10.1"
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
fi
fi
#ip="$(ifconfig | grep -A 1 'wlan0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
#ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
#wifi="$(ifconfig wlan0 | grep 'wlan0' | cut -d '"' -f 2)"
export ROS_HOSTNAME=$ip
export ROS_MASTER_URI=http://$ip:11311
#source /opt/ros/kinetic/setup.bash && nohup /opt/ros/kinetic/bin/roscore &
至此有线网络ip已经设置完成,主从机也已经配置完成,插上网线就可以接收主机发送的topic了,开心啊,再也不用担心网络延时啦!
参考文献:
(96条消息) linux eth0网卡配置详解_R0be1l的博客-CSDN博客_网卡eth0
(96条消息) grep -A -B -C -a -c -n -v -i等_You丶小明快跑的博客-CSDN博客
(96条消息) grep -A -B -C -a -c -n -v -i等_You丶小明快跑的博客-CSDN博客