1.查看虚拟机的子网IP,网关
2.编辑配置文件
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
IPADDR=192.168.200.10
NETMASK=255.255.255.0
BROADCAST=192.168.200.255
GATEWAY=192.168.200.2
ONBOOT=yes
USERCTL=NO
BOOTPROTO=static
#HWADDR=00:0C:29:47:82:BA
TYPE=Ethernet
IPV6NIT=no
DNS1=202.96.209.5
DNS2=8.8.8.8
3.重启网络服务
[root@localhost ~]# service network restart
4.查看更改之后的IP地址
第一种:
[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:47:82:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.200.10/24 brd 192.168.200.255 scope global eth0
inet6 fe80::20c:29ff:fe47:82ba/64 scope link
valid_lft forever preferred_lft forever
3: sit0: <NOARP> mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
第二种
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:47:82:BA
inet addr:192.168.200.10 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe47:82ba/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:53 errors:0 dropped:0 overruns:0 frame:0
TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3273 (3.1 KiB) TX bytes:12499 (12.2 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1626 errors:0 dropped:0 overruns:0 frame:0
TX packets:1626 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2806580 (2.6 MiB) TX bytes:2806580 (2.6 MiB)
5.测试能否上外网
能拼通之后使用ctrl+c退出
[root@localhost ~]# ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148: icmp_seq=1 ttl=128 time=213 ms
64 bytes from 220.181.38.148: icmp_seq=2 ttl=128 time=50.7 ms
64 bytes from 220.181.38.148: icmp_seq=3 ttl=128 time=145 ms
64 bytes from 220.181.38.148: icmp_seq=4 ttl=128 time=190 ms
64 bytes from 220.181.38.148: icmp_seq=5 ttl=128 time=169 ms
64 bytes from 220.181.38.148: icmp_seq=6 ttl=128 time=187 ms
--- baidu.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 9259ms
rtt min/avg/max/mdev = 50.773/159.322/213.499/52.844 ms
设置完静态IP之后,我们就可以通过xshell来连接主机了