1.确定主机及从机的IP地址(主从机需要在同一个网段)
查询计算机IP
ifconfig
xf@xf-Vostro-3670:~$ ifconfig
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.170 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::219d:a81b:fc74:9ea2 prefixlen 64 scopeid 0x20<link>
ether 8c:ec:4b:cc:f5:8d txqueuelen 1000 (以太网)
RX packets 406729 bytes 338826607 (338.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 256156 bytes 50472774 (50.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 294917 bytes 22558451 (22.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 294917 bytes 22558451 (22.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试主机IP为192.168.1.170,使用时需要改为自己的主机IP地址
xf@xf-ThinkPad-E15-Gen-2:~$ ifconfig
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 38:f3:ab:b1:d3:63 txqueuelen 1000 (以太网)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 342 bytes 35461 (35.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 342 bytes 35461 (35.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.132 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::57c5:e950:74d3:e629 prefixlen 64 scopeid 0x20<link>
ether 74:4c:a1:a6:7b:01 txqueuelen 1000 (以太网)
RX packets 25039 bytes 4992590 (4.9 MB)
RX errors 0 dropped 80 overruns 0 frame 0
TX packets 3624 bytes 777491 (777.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试从机IP为192.168.1.132,使用时需要改为自己的从机IP地址
2.修改主机名查询静态表
sudo vi /etc/hosts
修改主机hosts
127.0.0.1 localhost
127.0.1.1 xf-Vostro-3670
192.168.1.132 xf-ThinkPad-E15-Gen-2
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
修改从机hosts
127.0.0.1 localhost
127.0.1.1 xf-ThinkPad-E15-Gen-2
192.168.1.170 xf-Vostro-3670
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
3.修改.bashrc
主机.bashrc配置:在~/.bashrc文件最后添加
export ROS_MASTER_URI=http://192.168.1.170:11311
export ROS_HOSTNAME=192.168.1.170
从机.bashrc配置:在~/.bashrc文件最后添加
export ROS_MASTER_URI=http://192.168.1.170:11311
export ROS_HOSTNAME=192.168.1.132