您的位置:首页 > 理论基础 > 计算机网络

【Linux学习笔记⑦】Linux基本网络配置

2013-04-25 16:32 811 查看
主机名
查看:
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]#
临时修改:
[root@localhost ~]# hostname Hello
[root@localhost ~]# hostname
Hello
[root@localhost ~]#
永久修改:
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=NEWHOSTNAME   ;修改该值作为主机名
hosts
修改:
[root@localhost ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain    ;该行强烈建议保留
10.15.72.77 localhost localhost.localdomain    ;必须有三个字段:IP、FQDN、HOSTNAME
IP配置
临时配置:
[root@localhost ~]# ifconfig eth0 192.168.0.2 netmask 255.255.255.0     ;临时修改接口IP地址(需重启接口)
永久配置:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0     ifdown-ipv6    ifup          ifup-plip    ifup-wireless
ifcfg-lo       ifdown-post    ifup-bnep     ifup-post    net.hotplug
ifdown         ifdown-ppp     ifup-eth      ifup-ppp     network-functions
ifdown-bnep    ifdown-routes  ifup-ippp     ifup-routes  network-functions-ipv6
ifdown-eth     ifdown-sit     ifup-ipv6     ifup-sit
ifdown-ippp    ifdown-tunnel  ifup-isdn     ifup-tunnel
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0bak  ;修改前建议备份下
[root@localhost network-scripts]# vim ifcfg-eth0
DEVICE=eth0             ;指出设备名称
NM_CONTROLLED=yes       ;network mamager的参数,实时生效,不需要重启
ONBOOT=yes              ;设置为yes,开机自动启用网络连接
IPADDR=192.168.21.129   ;IP地址
BOOTPROTO=static        ;设置为none禁止DHCP,设置为static启用静态IP地址,设置为dhcp开启DHCP服务
NETMASK=255.255.255.0   #子网掩码
DNS1=8.8.8.8            ;第一个dns服务器
TYPE=Ethernet           ;网络类型为:Ethernet
GATEWAY=192.168.21.2    ;设置网关
DNS2=8.8.4.4            ;第二个dns服务器
IPV6INIT=no             ;禁止IPV6
USERCTL=no              ;是否允许非root用户控制该设备,设置为no,只能用root用户更改
HWADDR=00:0C:29:2C:E1:0F   ;网卡的Mac地址
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0"    ;定义设备名称
DEVICE、ONBOO、TBOOTPROTO、IPADDR、NETMASK、GATEWAY必须配置的
单网卡双IP
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0:0
#修改对应配置文件内容

MAC地址修改

[root@justin ~]# ifconfig eth0|grep HWaddr
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C5:F6:FF
[root@justin ~]# ifconfig eth0 down
[root@justin ~]# ifconfig eth0 hw ether 00:0C:29:28:28:28
[root@justin ~]# ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 00:0C:29:28:28:28
[root@justin ~]# ifconfig eth0 up
DNS

修改:
[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.100.189
nameserver 202.96.209.5
nameserver 202.96.209.133
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 210.22.70.3
路由

查看:

[root@justin ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.15.72.0      *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
default         10.15.72.254    0.0.0.0         UG    0      0        0 eth0
[root@justin ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.15.72.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         10.15.72.254    0.0.0.0         UG    0      0        0 eth0
[root@justin ~]#
静态路由添加:

[root@justin ~]# route add -net 192.168.3.0/24 gw 192.168.232.254
[root@justin ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.3.0     192.168.1.254   255.255.255.0   UG    0      0        0 eth0
10.15.72.0      *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
default         10.15.72.254    0.0.0.0         UG    0      0        0 eth0
[root@justin ~]# route del -net 192.168.3.0/24
默认网关
[root@justin ~]# route add default gw 10.15.72.254
[root@justin ~]# route del default gw 10.15.72.254


网络连接测试:

[root@justin ~]# traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1  10.15.72.254 (10.15.72.254)  0.715 ms  1.379 ms  1.600 ms
2  * * *
3  * * *
4  * * *
.....


PING
[root@localhost ~]# ping -c 4 192.168.0.1     ;指定发出ICMP包个数


ARP

[root@justin ~]# arp -n  ;查看当前系统的ARP表
Address                  HWtype  HWaddress           Flags Mask            Iface
10.15.72.100             ether   00:1e:c9:38:7b:d5   C                     eth0
10.15.72.73              ether   00:25:64:a6:08:af   C                     eth0
[root@justin ~]# arp -s 10.15.72.73 00:25:64:a6:08:af  ;绑定ip和mac
[root@justin ~]# arp -d 10.15.72.100 ;删除arp记录
[root@justin ~]# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
10.15.72.100                     (incomplete)                              eth0
10.15.72.73              ether   00:25:64:a6:08:af   CM                    eth0
[root@justin ~]#


本文出自 “水滴石穿” 博客,请务必保留此出处http://pengyl.blog.51cto.com/5591604/1186515
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: