zoukankan      html  css  js  c++  java
  • Linux网络基本配置

    一、网络接口配置文件
    [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
    # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
    DEVICE=eth0                 # 网卡接口名称
    BOOTPROTO=none              # 启用地址协议 --static:静态协议 --bootp协议 --dhcp协议 --none手工指定
    HWADDR=00:0C:29:2F:04:7E    # 网卡设备MAC地址
    IPADDR=192.168.1.26         # 网卡IP地址
    IPV6INIT=yes                # 是否支持IPv6【非必须】
    IPV6_AUTOCONF=yes           # IPv6是否自动配置【非必须】
    NETMASK=255.255.255.0       # 子网掩码
    BROADCAST=192.168.1.255     # 广播地址【非必须】
    GATEWAY=192.168.1.1         # 网关地址
    DNS1=192.168.1.1            # DNS1地址【非必须】
    ONBOOT=yes                  # 系统启动时是否自动加载
    TYPE=Ethernet               # 网络类型【非必须】
    PEERDNS=yes
    USERCTL=no


    二、网关配置文件(重启生效)
    [root@localhost ~]# vi /etc/sysconfig/network
    NETWORKING=yes                  # 设置Linux是否运行网络,取值为:yes/no
    NETWORKING_IPV6=yes             # 设置Linux是否支持IPv6
    HOSTNAME=localhost.localdomain  # 设置计算机的主机名


    三、DNS配置文件(重启生效)
    [root@localhost ~]# vi /etc/resolv.conf
    nameserver 202.109.14.5         # 主DNS
    nameserver 219.141.136.10       # 次DNS
    search localdomain              # DNS搜索路径,当解析不完整名称时默认的附加域名后缀


    四、主机名配置文件(相当于Windows下的 C:WindowsSystem32driversetchosts 文件)
    [root@localhost ~]# vi /etc/hosts
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1       localhost.localdomain localhost
    ::1             localhost6.localdomain6 localhost6


    五、网络操作相关命令
    1.查看网卡接口信息(默认列出所有接口)
    [root@localhost ~]# ifconfig


    2.临时配置eth0网络接口信息(无需重启)
    [root@localhost ~]# ifconfig eth0 192.168.1.26
    [root@localhost ~]# ifconfig eth0 192.168.1.26 netmask 255.255.255.0


    3.查看当前路由及网关信息
    [root@localhost ~]# netstat -r
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    192.168.1.0     *               255.255.255.0   U         0 0          0 eth0
    169.254.0.0     *               255.255.0.0     U         0 0          0 eth0
    default         localhost       0.0.0.0         UG        0 0          0 eth0


    4.网络服务相关命令
    [root@localhost ~]# service network stop          # 关闭网络服务
    [root@localhost ~]# service network start         # 启动网络服务
    [root@localhost ~]# service network restart       # 重启网络服务
    [root@localhost ~]# service network reload        # 重新载入 ifcfg-eth0 网络配置文件
    [root@localhost ~]# service network status        # 查看网卡状态查询

    [root@localhost ~]# /etc/init.d/network stop
    [root@localhost ~]# /etc/init.d/network start
    [root@localhost ~]# /etc/init.d/network restart
    [root@localhost ~]# /etc/init.d/network reload
    [root@localhost ~]# /etc/init.d/network status


    5.网卡接口关闭与激活
    [root@localhost ~]# ifdown eth0   # 关闭eth0网卡
    [root@localhost ~]# ifup eth0     # 激活eth0网卡

    参考文档
    http://linux.sheup.com/linuxs/list_12_1.htm
    http://my.oschina.net/adamboy/blog/35109
    http://hi.baidu.com/duangonghua/item/54e84b1fa9e143f686ad4e24
    http://www.cnblogs.com/huangfox/archive/2012/03/31/2426268.html

  • 相关阅读:
    Spring boot unable to determine jdbc url from datasouce
    Unable to create initial connections of pool. spring boot mysql
    spring boot MySQL Public Key Retrieval is not allowed
    spring boot no identifier specified for entity
    Establishing SSL connection without server's identity verification is not recommended
    eclipse unable to start within 45 seconds
    Oracle 数据库,远程访问 ora-12541:TNS:无监听程序
    macOS 下安装tomcat
    在macOS 上添加 JAVA_HOME 环境变量
    Maven2: Missing artifact but jars are in place
  • 原文地址:https://www.cnblogs.com/martinzhang/p/3535119.html
Copyright © 2011-2022 走看看