Press "Enter" to skip to content

Network Service

  • 检测网线是否连接
mii-tool  [-v, --verbose] [-V, --version] [-R, --reset] [-r, --restart] [-w, --watch] [-l, --log] [-A, --advertise=media,...]  [-F, --force=media] [inter-
       face ...]

例如:

[root@kyle /]# mii-tool
eth0: negotiated 100baseTx-FD, link ok
  • 查看或者临时配置网络
ifconfig interface [aftype] options | address ...

例如:
将IP绑定到2.2.2.254,netmask设置为255.255.255.0(临时)

[root@kyle /]# ifconfig eth0 2.2.2.254 netmask 255.255.255.0
  • 启动网卡
ifup <device name>
  • 关闭网卡
ifdown <设备名>
  • 查看或修改主机名(临时)
hostname [-v] [-a] [--alias] [-d] [--domain] [-f] [--fqdn] [-i] [--ip-address] [--long] [-s] [--short] [-y] [--yp] [--nis] [-n] [--node]

例如:

[root@kyle /]# hostname kyle.redhat.com
[root@kyle /]# hostname
kyle.redhat.com
  • 修改主机名
    修改主机名步骤:
    1)hostname
    2)修改/etc/sysconfig/network中的HOSTNAME

例如:

[root@kyle /]# hostname kyle.redhat.com
[root@kyle /]# vim /etc/sysconfig/network                                //修改HOSTNAME=kyle.redhat.com
[root@kyle /]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=kyle.redhat.com
  • 修改IP地址(永久)
/etc/sysconfig/network-scripts/ifcfg-ethX

例如:

[root@kyle /]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C
DEVICE=eth0
BOOTPROTO=static              //static为静态IP,dhcp为自动获取
NETMASK=255.255.255.0         //子网掩码
GATEWAY=2.2.2.1               //网关
IPADDR=2.2.2.254              //绑定的IP地址
HWADDR=00:27:19:96:B0:CD      //MAC地址
ONBOOT=yes                    //重启网络服务时自动启动

注意:修改完配置文件要重启网络服务(service network restart)

  • 本地DNS解析文件
/etc/hosts

格式:

IP                                        servername

例如:

[root@kyle /]# cat /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
2.2.2.254       kyle.redhat.com kyle
2.2.2.192       teacher.redhat.com      teacher
  • 配置DNS服务器地址
/etc/resolv.conf

格式:

nameserver                        IP

例如:

[root@kyle /]# cat /etc/resolv.conf
search localdomain
nameserver 8.8.8.8
  • 设定DNS解析的优先级(本地或查找nameserver)
/etc/nsswitch.conf

hosts: files dns //先查找本地文件,再查找DNS服务器

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *