先输入ifconfig,知道网卡名是:ens33
[root@bogon ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.128 netmask 255.255.255.0 broadcast 192.168.88.255
得到临时配IP地址命令:
ifconfig ens33 192.168.88.128
在另外两台也分别配IP:
ifconfig ens33 192.168.88.131
ifconfig ens33 192.168.88.132
看看有没人在用某个IP地址
[root@bogon share]# arping -I ens33 192.168.88.131
看看ifconfig是哪个文件产生的
[root@bogon share]# which ifconfig
/usr/sbin/ifconfig
是哪个包产生的文件?
[root@bogon share]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.22.20131004git.el7.x86_64
[root@bogon share]#
命令:
[root@bogon share]# ip add show
ens33是物理网卡
lo是回款地址,测试用的,127.0.0.1
开发可以在虚拟机自己写个软件,与本机的WINDOWS当客户端,用192.168.88.128连接
开发不用虚拟机开发软件,也用WINDOWS开发,就用127.0.0.1与客户端连接
mtu 1500:网卡一次性能传送1500个字节
inet6 fe80::8ef4:d045:bb20:5d0a:IPV6的地址,不要管它,我们用的都是IPV4的地址,就是192.168.88.128
ether 00:0c:29:56:c5:2f:mark地址
[root@bogon share]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.128 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::8ef4:d045:bb20:5d0a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:56:c5:2f txqueuelen 1000 (Ethernet)
RX packets 8789 bytes 965842 (943.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15287 bytes 2244339 (2.1 MiB)
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 1 (Local Loopback)
RX packets 28 bytes 2144 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28 bytes 2144 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:c4:7b:7d txqueuelen 1000 (Ethernet)
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
改IP的命令
[root@bogon share]# ifconfig ens33 192.168.88.128/24
1、下面都是临时修改:
配DNS
[root@bogon share]# vim /etc/resolv.conf
根据DNS来改:
老师的界面
配网关,添加默认网关,把网关地址写出来
[root@bogon share]# route add default gw 192.168.1.1 network 255.255.255.0
老师的界面:
0.0.0.0/0.0.0.0代表所有的IP地址或子网
查看
[root@bogon share]# route -n
老师的界面:
删网关:
[root@bogon ~]# route del default gw 192.168.1.1 network 255.255.255.0
我的运行结果:
删除网关:
[root@bogon ~]# route del default gw 192.168.88.2
[root@bogon ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.88.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@bogon ~]# route del default gw 192.168.1.1
SIOCDELRT: 没有那个进程
添加网关:
[root@bogon ~]# route add default gw 192.168.88.2 netmask 255.255.255.0
[root@bogon ~]# route -n
网关Gateway为0.0.0.0代表内网访问,不需要网关
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.88.2 255.255.255.0 UG 0 0 0 ens33
192.168.88.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@bogon ~]#
2、永久修改:
[root@bogon ~]# cd /etc/sysconfig/network-scripts/
[root@bogon network-scripts]# ls
ifcfg-ens33 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[root@bogon network-scripts]#
用命令:
[root@bogon network-scripts]# vim ifcfg-ens33
得到:dhcp是自动获取网络地址的意思
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
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="ens33"
UUID="a2c8cc27-b372-4110-ac17-23e1132cd249"
DEVICE="ens33"
ONBOOT="yes"
保存退出:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
IPADDR=192.168.88.131
NETMASK=255.255.255.0
GATEWAY=192.168.88.2
DNS1=202.106.195.68
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="ens33"
UUID="a2c8cc27-b372-4110-ac17-23e1132cd249"
DEVICE="ens33"
ONBOOT="yes"
重启网络服务:
[root@bogon network-scripts]# systemctl restart network
[root@bogon network-scripts]#
查看:
[root@bogon network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 202.106.195.68
[root@bogon network-scripts]#
还可以配多个DNS
[root@bogon network-scripts]# systemctl restart network
IP没变:
[root@bogon network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.131 netmask 255.255.255.0 broadcast 192.168.88.255
网关也没变:
[root@bogon network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.88.2 0.0.0.0 UG 100 0 0 ens33
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@bogon network-scripts]# cat /etc/resolv.conf
多了一个nameserver
# Generated by NetworkManager
nameserver 202.106.195.68
nameserver 202.106.46.151
[root@bogon network-scripts]#
把百度翻译成:61.135.169.121的IP地址
[root@bogon ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
在没有DNS下,可以用hosts来帮自己解析,例如可以自己设置网址,让自己另一台计算机连这个网,我可以开两个虚拟机,看看他们的IP,一台是192.168.88.131
在名字为learn的虚拟机上
[root@bogon ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.88.131 learn1
[root@bogon ~]# ping learn1
PING learn1 (192.168.88.131) 56(84) bytes of data.
64 bytes from learn1 (192.168.88.131): icmp_seq=1 ttl=64 time=0.630 ms
64 bytes from learn1 (192.168.88.131): icmp_seq=2 ttl=64 time=0.334 ms
这样不同的机器设置同一个域名,就可以访问
修改主机名的方法:
[root@bogon ~]# hostname
bogon
[root@bogon ~]# hostnamectl set-hostname learn1
[root@bogon ~]# hostname
learn1
[root@bogon ~]#
上面还是bogon,用exit退出后重新连接,就得到learn1了