Linux 网络配置基础 1

    网络相关命令与网卡配置文件

    OS:Red**Hat EnterpriseLinux6.4
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图1
    1 ifconfig 查看 / 设置网卡**

    ifconfig 查看所有活动网卡信息
    ifconfig -a 查看所有网卡信息
    ifconfig eth0 查看具体网卡信息
    ifconfig eth0 up/down 激活 / 禁用网卡
    ifup/ifdown eth0 激活 / 禁用网卡(重新读取配置文件)
    [root@rhel64 ~]# ifconfig
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图2

    查看具体网卡信息
    [root@rhel64 ~]# ifconfig eth0
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图3

    临时设置 eth0 网卡子接口 ip,子网卡 ip 须使用静态配置。
    [root@rhel64 ~]# ifconfig eth0:0 192.168.7.101
    [root@rhel64 ~]# ifconfig
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图4

    [root@rhel64 ~]# ifconfig eth0:0 down
    [root@rhel64 ~]# ifconfig
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图5

    2 ip、ethtool 查看网卡配置、属性

    [root@rhel64 ~]# ip
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图6

    查看网络接口配置情况
    [root@rhel64 ~]# ip addr
    [root@rhel64 ~]# ip addr show eth0
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图7

    查看网络接口属性信息
    [root@rhel64 ~]# ethtool eth0
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图8

    3 ping 测试网络通信
    [root@rhel64 ~]# ping 192.168.6.6 -c 4
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图9

    4 route -n 查看路由信息
    [root@rhel64 ~]# route -n
    [root@rhel64 ~]# ip route
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图10

    如果需手动指定具体路由,可编辑修改配置文件
    /etc/sysconfig/network-scripts/route-eth0

    5 traceroute 查看主机间路由

    测试从当前主机到目标主机间经过的网络节点
    [root@rhel64 ~]# traceroute 192.168.6.6
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图11

    windows 中对应命令 tracert
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图12

    6 hostname 查看主机名
    [root@rhel64 ~]# hostname
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图13

    hostname 命令也可以用来临时设置主机名,当前有效,重启后恢复配置文件中值

    7 netstat 查看网络连接状态
    [root@rhel64 ~]# netstat —help
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图14

    [root@rhel64 ~]# netstat -lntup
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图15

    [root@rhel64 ~]# netstat -antup
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图16

    8 /etc/sysconfig/network
    全局配置文件
    [root@rhel64 ~]# cat /etc/sysconfig/network
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图17

    NETWORKING 全局网络开关
    HOSTNAME 主机名
    GATEWAY 全局网关配置,多个网卡时可在具体网卡配置文件指定

    9 具体网卡配置文件

    [root@rhel64 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图18

    DEVICE 网卡名称 要与配置文件名中一致
    TYPE=Ethernet 以太网
    ONBOOT=yes 重启操作系统后激活网卡
    BOOTPROTO none 或者 static 是静态设置 ip;dhcp 是自动获取
    IPADDR ip 地址
    GATEWAY 网关 默认路由
    PREFIX 子网掩码,或使用 NETMASK=255.255.255.0

    10 本地主机名解析 /etc/hosts
    保存主机名与 IP 地址的映射记录
    [root@rhel64 ~]# cat /etc/hosts
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图19

    [root@rhel64 ~]# vi /etc/hosts
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图20

    [root@rhel64 ~]# ping rhel64 -c2
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图21

    win7 中也有对应文件
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图22

    11 网络配置总结
    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图23

    【Linux】Linux网络配置基础1 网络相关命令与网卡配置文件_ITPUB博客 - 图24

    吕星昊
    2016.1.18

    来自 “ITPUB 博客” ,链接:http://blog.itpub.net/29475508/viewspace-1978184/,如需转载,请注明出处,否则将追究法律责任。
    http://blog.itpub.net/29475508/viewspace-1978184/