Linux(CentOS)下,设置IP/Netmask/Gateway等
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
原来的服务器(IP:115.238.54.116),新增的服务器(IP:115.238.73.175);
打算给原服务器和新服务器分别设置一个内网IP(192.168.0.2和192.168.0.3)。
# ifconfig em2 192.168.0.2 netmask 255.255.255.0
这种方法,可以设置,但重启后,会丢失;所以,用如下方法!
先查看原有的网络配置。
# cd /etc/sysconfig/network-scripts
# ll
-rw-r--r--. 1 root root 207 Jul 5 02:49 ifcfg-em1#网卡1
-rw-r--r--. 1 root root 187 Jul 5 02:50 ifcfg-em1:1
-rw-r--r--. 1 root root 135 Jul 4 01:14 ifcfg-em2#网卡2
-rw-r--r--. 1 root root 254 Jan 9 2013 ifcfg-lo
# cat ifcfg-em1:1
DEVICE="em1:1"
BOOTPROTO="static"
HWADDR="F0:1F:AF:D6:17:DD"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="99c6d8e1-db70-4c66-af7f-d074201c64ef"
IPADDR="120.199.8.215"
NETMASK="255.255.255.240"
用原有的配置,新建一个配置,修改其IPADDR和NETMAST。
# vi ifcfg-em2
DEVICE="em2"
BOOTPROTO="static"
HWADDR="F0:1F:AF:D6:17:DE"
NM_CONTROLLED="yes"
ONBOOT="yes"
NETMASK="255.255.255.0"
TYPE="Ethernet"
UUID="b46afc5c-019a-4415-8e40-7c2066ec28be"
IPADDR= 192.168.0.2
NETMASK= 255.255.255.0
重启一下网络服务。
# service network restart
也可以通过如下命令启动或关闭它:
# ifup em2
# ifdown em2
查看设置的结果(多出了新建的em1:2)。
# ifconfig
root@localhost network-scripts]# ifconfig
em1 Link encap:Ethernet HWaddr C8:1F:66:B8:EB:9E
em1:1 Link encap:Ethernet HWaddr C8:1F:66:B8:EB:9E
em2 Link encap:Ethernet HWaddr F0:1F:AF:D6:17:DE
inet addr: 192.168.0.2 Bcast:192.168.0.255 Mask: 255.255.255.0
inet6 addr: fe80::f21f:afff:fed6:17de/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2933 errors:0 dropped:0 overruns:0 frame:0
TX packets:2957 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:187927 (183.5 KiB) TX bytes:232729 (227.2 KiB)
Interrupt:17
lo Link encap:Local Loopback
查看路由网关(多出了一个192.168.*)。
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
115.238.54.96 0.0.0.0 255.255.255.224 U 0 0 0 em1
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 em1#小网络,Class C(局域网)
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1#大网络,Class B
0.0.0.0 115.238.73.161 0.0.0.0 UG 0 0 0 em1#网关,Class A(UG: Up Gateway)
查看网络是否ping得通。
# ping -c 3 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=0.037 ms
64 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=0.024 ms
--- 192.168.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.024/0.033/0.040/0.009 ms
打算给原服务器和新服务器分别设置一个内网IP(192.168.0.2和192.168.0.3)。
# ifconfig em2 192.168.0.2 netmask 255.255.255.0
这种方法,可以设置,但重启后,会丢失;所以,用如下方法!
先查看原有的网络配置。
# cd /etc/sysconfig/network-scripts
# ll
-rw-r--r--. 1 root root 207 Jul 5 02:49 ifcfg-em1#网卡1
-rw-r--r--. 1 root root 187 Jul 5 02:50 ifcfg-em1:1
-rw-r--r--. 1 root root 135 Jul 4 01:14 ifcfg-em2#网卡2
-rw-r--r--. 1 root root 254 Jan 9 2013 ifcfg-lo
# cat ifcfg-em1:1
DEVICE="em1:1"
BOOTPROTO="static"
HWADDR="F0:1F:AF:D6:17:DD"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="99c6d8e1-db70-4c66-af7f-d074201c64ef"
IPADDR="120.199.8.215"
NETMASK="255.255.255.240"
用原有的配置,新建一个配置,修改其IPADDR和NETMAST。
# vi ifcfg-em2
DEVICE="em2"
BOOTPROTO="static"
HWADDR="F0:1F:AF:D6:17:DE"
NM_CONTROLLED="yes"
ONBOOT="yes"
NETMASK="255.255.255.0"
TYPE="Ethernet"
UUID="b46afc5c-019a-4415-8e40-7c2066ec28be"
IPADDR= 192.168.0.2
NETMASK= 255.255.255.0
重启一下网络服务。
# service network restart
也可以通过如下命令启动或关闭它:
# ifup em2
# ifdown em2
查看设置的结果(多出了新建的em1:2)。
# ifconfig
root@localhost network-scripts]# ifconfig
em1 Link encap:Ethernet HWaddr C8:1F:66:B8:EB:9E
em1:1 Link encap:Ethernet HWaddr C8:1F:66:B8:EB:9E
em2 Link encap:Ethernet HWaddr F0:1F:AF:D6:17:DE
inet addr: 192.168.0.2 Bcast:192.168.0.255 Mask: 255.255.255.0
inet6 addr: fe80::f21f:afff:fed6:17de/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2933 errors:0 dropped:0 overruns:0 frame:0
TX packets:2957 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:187927 (183.5 KiB) TX bytes:232729 (227.2 KiB)
Interrupt:17
lo Link encap:Local Loopback
查看路由网关(多出了一个192.168.*)。
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
115.238.54.96 0.0.0.0 255.255.255.224 U 0 0 0 em1
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 em1#小网络,Class C(局域网)
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 em1#大网络,Class B
0.0.0.0 115.238.73.161 0.0.0.0 UG 0 0 0 em1#网关,Class A(UG: Up Gateway)
查看网络是否ping得通。
# ping -c 3 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=0.037 ms
64 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=0.024 ms
--- 192.168.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.024/0.033/0.040/0.009 ms
两台机器都设置好内网IP后,相互可以ping得通。
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献17条内容
所有评论(0)