Linux基础知识学习——第四天:配置网络ip地址

一、ifconfig查看网络信息

[root@ORCL ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.198.142  netmask 255.255.255.0  broadcast 192.168.198.255
        inet6 fe80::8fa3:84d5:c0be:76b5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:12:4f:f3  txqueuelen 1000  (Ethernet)
        RX packets 30748  bytes 2196457 (2.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 54570  bytes 71048735 (67.7 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 1000  (Local Loopback)
        RX packets 3344  bytes 236121 (230.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3344  bytes 236121 (230.5 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:f7:83:20  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

二、ping测试主机之间的网络

2.1 基本语法

//用来测试当前服务器是否可以连接目标主机
ping 目标主机

2.2 测试当前服务器是否可以连接宿主机

[root@ORCL ~]# ping 192.168.198.1
PING 192.168.198.1 (192.168.198.1) 56(84) bytes of data.
64 bytes from 192.168.198.1: icmp_seq=1 ttl=128 time=0.297 ms
64 bytes from 192.168.198.1: icmp_seq=2 ttl=128 time=0.317 ms
64 bytes from 192.168.198.1: icmp_seq=3 ttl=128 time=0.226 ms

可以ping通。

2.2 测试当前服务器是否可以连接百度

[root@ORCL ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.14) 56(84) bytes of data.
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=1 ttl=128 time=10.5 ms
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=2 ttl=128 time=11.1 ms
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=3 ttl=128 time=10.6 ms

可以ping通。

三、修改IP地址为固定的

3.1 ifconfig查看一下网络信息

在这里插入图片描述

找到ifcfg-ens33文件,修改其内容。

3.2 修改IP配置文件

[root@ORCL ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

在这里插入图片描述

3.3 重启网络

[root@ORCL ~]# service network restart
Restarting network (via systemctl):  
                                                           [  OK  ]

四、修改IP地址后可能遇到的问题

(1)物理机器能ping通虚拟机,但是虚拟机ping不通物理机,一般都是因为物理机的防火墙问题,把物理机防火墙关闭就行.
(2)虚拟机能ping通物理机,但是虚拟机ping不通外网,一般都是因为DNS的设置有问题.
(3)虚拟机 ping www.baidu.com 显示域名未知等信息,一般查看GATEWAY和DNS设置是否正确.
(4)如果以上全部设置完还是不行,需要关闭NetworkManager服务.
关闭: systemctl stop NetworkManager
禁用: systemctl disable NetworkManager
(5)如果检查发现systemctl status network 有问题,需要检查ifcgf-ens33

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蜗的房子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值