linux 常规网络配置

主机名设置
[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=red1
GATEWAY=10.3.37.1
查看主机名
[root@localhost ~]# hostname
localhost.red1

使用ipconfig 配置IP及辅助IP
[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:9A:A7:44 
          inet addr:10.3.37.30  Bcast:10.3.37.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe9a:a744/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:69301 errors:0 dropped:0 overruns:0 frame:0
          TX packets:817 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:6539421 (6.2 MiB)  TX bytes:122965 (120.0 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:29358 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29358 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:27503811 (26.2 MiB)  TX bytes:27503811 (26.2 MiB)

peth0     Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:128574 errors:0 dropped:0 overruns:0 frame:0
          TX packets:872 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:15894159 (15.1 MiB)  TX bytes:132803 (129.6 KiB)
          Interrupt:18 Base address:0x2000

vif0.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:843 errors:0 dropped:0 overruns:0 frame:0
          TX packets:69326 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:127005 (124.0 KiB)  TX bytes:6541353 (6.2 MiB)

xenbr0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:67878 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5309365 (5.0 MiB)  TX bytes:0 (0.0 b)
设置IP地址
[root@localhost ~]# ifconfig eth0 10.3.37.31 netmask 255.255.255.0
禁用和启用网卡
[root@localhost ~]# ifconfig eth0 down
[root@localhost ~]# ifconfig eth0 up
[root@localhost ~]# ifdown eth0
[root@localhost ~]# ifup eth0
更改MAC地址
[root@localhost ~]# ifconfig eth0 down
[root@localhost ~]# ifconfig  eth0 hw ether 00:00:00:00:00:00
[root@localhost ~]# ifconfig eth0 up
rounte设置网关
route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.3.37.0       *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth0
default         10.3.37.1       0.0.0.0         UG    0      0        0 eth0
U 表示该条路由活跃  G表示该条路由涉及到网关
[root@localhost ~]# route  add default gw IP #添加默认网关
[root@localhost ~]# route  del default gw IP #删除默认网关
网卡配置文件
[root@localhost /]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.3.37.255
HWADDR=00:0C:29:9A:A7:44
IPADDR=10.3.37.30
IPV6ADDR=
IPV6PREFIX=
NETMASK=255.255.255.0
NETWORK=10.3.37.0
ONBOOT=yes
[root@localhost ~]# ifdown eth0
[root@localhost ~]# ifup eth0

setup命令
调出文本界面配置

修改resolv.conf设置DNS
vi /etc/resolv.conf

猜你喜欢

转载自sunshinelives.iteye.com/blog/1054967
今日推荐