Linuxベースネットワーク設定
27697 ワード
linuxネットワークパラメータの表示
> [root@localhost ~]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:33:4A:0C
inet addr:192.168.4.115 Bcast:192.168.4.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe33:4a0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8133 errors:0 dropped:0 overruns:0 frame:0
TX packets:5861 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:818322 (799.1 KiB) TX bytes:835205 (815.6 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:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:946 (946.0 b) TX bytes:946 (946.0 b)
[root@localhost ~]# hostname
localhost
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.4.0 * 255.255.255.0 U 1 0 0 eth1
default localhost 0.0.0.0 UG 0 0 0 eth1
[root@localhost ~]# netstat -antput
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:875 0.0.0.0:* LISTEN 2262/rpc.rquotad
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1963/rpcbind
tcp 0 0 0.0.0.0:33073 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:40337 0.0.0.0:* LISTEN 2266/rpc.mountd
tcp 0 0 0.0.0.0:53586 0.0.0.0:* LISTEN 2010/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2345/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2590/master
tcp 0 0 0.0.0.0:35161 0.0.0.0:* LISTEN 2266/rpc.mountd
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:42759 0.0.0.0:* LISTEN 2266/rpc.mountd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3041/mysqld
tcp 0 756 192.168.4.115:22 192.168.4.105:52347 ESTABLISHED 2788/sshd
tcp 0 0 :::111 :::* LISTEN 1963/rpcbind
tcp 0 0 :::53461 :::* LISTEN 2266/rpc.mountd
tcp 0 0 :::22 :::* LISTEN 2345/sshd
tcp 0 0 ::1:631 :::* LISTEN 2084/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2590/master
tcp 0 0 :::60442 :::* LISTEN 2266/rpc.mountd
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (123.125.65.78) 56(84) bytes of data.
64 bytes from 123.125.65.78: icmp_seq=1 ttl=56 time=141 ms
64 bytes from 123.125.65.78: icmp_seq=2 ttl=56 time=18.9 ms
64 bytes from 123.125.65.78: icmp_seq=3 ttl=56 time=17.3 ms
64 bytes from 123.125.65.78: icmp_seq=4 ttl=56 time=19.9 ms
[root@localhost ~]# nslookup
> www.baidu.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 123.125.65.78
Name: www.a.shifen.com
Address: 123.125.65.82
[root@localhost ~]# traceroute www.baidu.com
traceroute to www.baidu.com (119.75.218.70), 30 hops max, 60 byte packets
1 192.168.40.1 (192.168.40.1) 1.223 ms 3.555 ms 4.307 ms
2 117.100.128.1 (117.100.128.1) 8.126 ms 8.927 ms 8.623 ms
3 124.205.97.48 (124.205.97.48) 8.430 ms 8.248 ms 8.100 ms
4 219.239.249.25 (219.239.249.25) 7.906 ms 7.953 ms 7.887 ms
5 14.197.177.9 (14.197.177.9) 7.874 ms 14.197.178.45 (14.197.178.45) 7.672 ms 14.197.178.41 (14.197.178.41) 7.485 ms
6 14.197.253.49 (14.197.253.49) 11.445 ms * *
linuxネットワークパラメータの構成
一.一時的な構成:一般的にコマンドで構成され、すぐに有効になり、再起動が無効になります.
[root@localhost ~]# ifconfig eth1 192.168.40.20 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth1 192.168.40.20/32
[root@localhost ~]# ifconfig eth1 down
[root@localhost ~]# ifconfig eth1 up
[root@localhost ~]# ifdown eth1
[root@localhost ~]# ifup eth1
[root@localhost ~]# service network restart
[root@localhost ~]# ifconfig eth1:0 10.1.1.1
[root@localhost ~]# route add -net 192.148.40.0/32 gw 192.148.40.1
[root@localhost ~]# route del -net 192.148.40.0/32
[root@localhost ~]# route add default gw 192.168.4.1
[root@localhost ~]# route del default gw 192.168.4.1
[root@localhost ~]# hostname zhangsan
[root@localhost ~]# bash
[root@zhangsan ~]#
二.≪固定構成|Fixed Configuration|ldap≫:一般的には構成ファイルを変更し、再起動する必要があります.
DEVICE=eth0 #
ONBOOT=yes #
BOOTPROTO=static (dhcp) #
IPADDR=192.168.4.1 #ip
NETMASK=255.255.255.0 #
GATEWAY=192.168.4.2 #
DNS1=202.106.0.20 # DNS
[root@zhangsan ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost
[root@zhangsan ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1
nameserver 192.168.4.1
[root@zhangsan ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@zhangsan ~]# service network restart
[root@zhangsan ~]# ifdown eth1
[root@zhangsan ~]# ifup eth1