Linux 常用网络配置命令

 显示网路配置

  ifconfig  

    ifconfig –a  查看所有接口

    ifconfig device 查看指定网络接口信息

配置网络地址 网关 广播地址 子网掩码

       ifconfig eth0 192.168.1.50 netmask 255.255.255.0 broadcast 192.168.1.50

       route add default gw 192.168.1.20 添加网关

       route delet default 删除默认网关

       ip route  (route) 显示路由

 以上设置在系统重新启动时就会失去,必须要写入到配置文件/etc/sysconfig/network-srcipts/ifcfg-eth0中去:

 系统的主机名称在配置文件/etc/sysconfig/network

修改这些配置文件后重启网络服务就会生效(/etc/init.d/network restart

 相关 route命令的用法:

    route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0

              adds a route to the network 192.56.76.x via "eth0". The Class C

              netmask  modifier is not really necessary here because 192.* is

              a Class C IP address. The word "dev" can be omitted here.

      Flags  Possible flags include

               U (route is up)

              H (target is a host)

              G (use gateway)

              R (reinstate route for dynamic routing)

              D (dynamically installed by daemon or redirect)

              M (modified from routing daemon or redirect)

              A (installed by addrconf)

              C (cache entry)

              !  (reject route)  

  还有一个强大网络配置工具(ip),它是iproute2软件包里面的一个工具,能替代传统的网络配置工具(ifconfig route),而且能够实现更多的功能:

      ip linkip link show 显示系统网络设备

[root@mail net]# ip link

1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000

    link/ether 00:0c:29:2f:1c:e1 brd ff:ff:ff:ff:ff:ff

3: sit0: <NOARP> mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

ip addr  显示网络地址

[root@mail net]# ip addr

1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000

    link/ether 00:0c:29:2f:1c:e1 brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.50/24 brd 192.168.1.255 scope global eth0

    inet6 fe80::20c:29ff:fe2f:1ce1/64 scope link tentative

       valid_lft forever preferred_lft forever

3: sit0: <NOARP> mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

ip addr { add | del } IFADDR dev STRING 为某一设备添加或删除ip

设置链路属性 ip link set DEVICE { up | down | arp { on | off } |

               promisc { on | off } |

               allmulti { on | off } |

               dynamic { on | off } |

               multicast { on | off } |

               txqueuelen PACKETS |

               name NEWNAME |

               address LLADDR | broadcast LLADDR |

               mtu MTU }

ip route show / ip route list

ip route list table (main /local / default)

ip route { add | del | change | append | replace | monitor } ROUTE

ip route add default via 192.168.1.20 添加网关

ip route delete default 删除网关