目录
(完美解决每次ssh连接时ip变化问题;Centos版本)
0.查看ip地址【ifconfig】
[root@localhost rocketmq]# ifconfig
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.154 netmask 255.255.255.0 broadcast 192.168.21.255
inet6 fe80::d59f:a7d7:3cef:2cf7 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:79:30:c8 txqueuelen 1000 (Ethernet)
RX packets 112359 bytes 69574284 (66.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 66233 bytes 21848580 (20.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost rocketmq]#
1.查看dhcp下的默认网关【route -n】
[root@localhost rocketmq]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.21.2 0.0.0.0 UG 100 0 0 ens37
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.21.0 0.0.0.0 255.255.255.0 U 100 0 0 ens37
[root@localhost rocketmq]#
默认为第一条 192.168.21.2 这里很重要。
2.修改网络配置,我这里的连接方式是ens37
[root@localhost rocketmq]# vim /etc/sysconfig/network-scripts/ifcfg-ens37
#修改内容如下:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" #这里需要改由dhcp改为static
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens37"
UUID="743b7e9f-0aa3-41e0-8dec-9b5bf3b32f92"
DEVICE="ens37"
ONBOOT="yes" #这里需要改由no改为yes
IPADDR=192.168.248.136 #这里改为你的静态ip地址
NETMASK=255.255.255.0 #掩码
DNS1=8.8.8.8 #代理dns服务器
GATEWAY=192.168.21.2 #这里写前面查找到的默认网关
使用:wq保存退出
3.重启网卡
[root@localhost rocketmq]# service network restart
4.使用ifconfig查看ip地址是否改变
[root@localhost rocketmq]# ifconfig
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.154 netmask 255.255.255.0 broadcast 192.168.21.255
inet6 fe80::d59f:a7d7:3cef:2cf7 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:79:30:c8 txqueuelen 1000 (Ethernet)
RX packets 112359 bytes 69574284 (66.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 66233 bytes 21848580 (20.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost rocketmq]#
5.检测网络是否还能连通
使用ping www.baidu.com
[root@localhost rocketmq]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.96) 56(84) bytes of data.
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=1 ttl=128 time=18.3 ms
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=2 ttl=128 time=27.7 ms
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=3 ttl=128 time=23.1 ms
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=4 ttl=128 time=33.6 ms
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=5 ttl=128 time=30.5 ms
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=6 ttl=128 time=11.2 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5058ms
rtt min/avg/max/mdev = 11.289/24.116/33.607/7.559 ms
从结果可以看出网络也能连通
配置过程中遇到啥问题欢迎留言!!!!