中国数据网
http://www.dbchina.net
收藏本页
联系我们
 
Linux系统中网络配置详解(2) ~ admin
(实际上,以上仅仅是/etc/services的一部分,限于篇幅没有全部写出)

在这个文件中,为了安全考虑,我们可以修改一些常用服务的端口地址,例如我们可以把telnet服务的端口地址改为52323,www的端口改为8080,ftp端口地址改为2121等等,这样仅仅需要在应用程序中修改相应的端口即可.这样可以提高系统的安全性.

/etc/inetd.conf文件是inetd的配置文件, 首先要了解一下linux服务器到底要提供哪些服务。一个很好的原则是" 禁止所有不需要的服务",这样黑客就少了一些攻击系统的机会./etc/inetd.conf范例文件如下:

#

# inetd.confThis file describes the services that will be available

#  through the INETD TCP/IP super server. To re-configure

#  the running INETD process, edit this file, then send the

#  NETD process a SIGHUP signal.

#

# Version:  @(#)/etc/inetd.conf 3.10 05/27/93

#

# Authors:  Original taken from BSD UNIX 4.3/TAHOE.

# Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>

#

# Modified for Debian Linux by Ian A. Murdock <imurdock@shell.portal.com>

#

# Modified for RHS Linux by Marc Ewing <marc@redhat.com>

#

#

#服务名 socket类型 协议 动作 拥有者 服务进程路径名 掉用参数

#nowait 表示在相应一个网络连接之后,服务进程在释放旧的联接之前可以接受

#新的连接请求,wait 则表示必须在旧连接清除之后才能接收新的连接.

# Echo, discard, daytime, and chargen are used primarily for testing.

# To re-read this file after changes, just do a 'killall -HUP inetd'

#

#echo  stream  tcp  nowait  root  internal

#echo  dgram udp  wait root  internal

#discard  stream  tcp  nowait  root  internal

#discard  dgram udp  wait root  internal

#daytime stream  tcp nowait root internal

#daytime dgramudp wait  root internal

#chargen stream  tcp nowait  root  internal

#chargen dgram  udp  wait root internal

#time stream tcp nowait root  internal

#time dgram udp wait root internal

#

# These are standard services.

#

ftp stream tcp nowait root /usr/sbin/tcpd in.wuftpd -l -a

telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd

#

# Shell, login, exec, comsat and talk are BSD protocols.

#

#shell  stream  tcp  nowait  root /usr/sbin/tcpd in.rshd

#login  stream  tcp  nowait  root /usr/sbin/tcpd in.rlogind

#exec  stream  tcp  nowait  root /usr/sbin/tcpd in.rexecd

#comsat dgram  udp  wait root /usr/sbin/tcpd in.comsat

#talk  dgram  udp  wait root /usr/sbin/tcpd in.talkd

#ntalk  dgram  udp wait root /usr/sbin/tcpd in.ntalkd

#dtalk  stream tcp  waut nobody  /usr/sbin/tcpd in.dtalkd

# Pop and imap mail services et al

#

#pop-2 stream tcp nowait root /usr/sbin/tcpd ipop2d

#pop-3 stream tcp nowait root /usr/sbin/tcpd ipop3d

#imap stream tcp nowait root /usr/sbin/tcpd imapd

#

# The Internet UUCP service.

#

#uucp stream tcp nowait uucp /usr/sbin/tcpd /usr/lib/uucp/uucico -l

#

# Tftp service is provided primarily for booting. Most sites

# run this only on machines acting as "boot servers." Do not uncomment

# this unless you *need* it.

#

#tftp  dgram  udp  wait  root  /usr/sbin/tcpd  in.tftpd

#bootps dgram  udp  wait  root  /usr/sbin/tcpd  bootpd

# 

# Finger, systat and netstat give out user information which may be

# valuable to potential "system crackers." Many sites choose to disable

# some or all of these services to improve security.

#

#finger stream  tcp nowait root /usr/sbin/tcpd in.fingerd

#cfinger stream  tcp nowait root /usr/sbin/tcpd in.cfingerd

#systat stream  tcp nowait guest /usr/sbin/tcpd /bin/ps -auwwx

#netstat stream  tcp nowait guest /usr/sbin/tcpd /bin/netstat  -f inet

#

# Authentication

#

#auth  stream  tcp  nowait  nobody  /usr/sbin/in.identd in.identd -l -e -o

#linuxconf stream tcp  wait root /bin/linuxconf linuxconf -http

大家看到的这个文件已经修改过的文件,除了telnet 和ftp服务,其他所有的服务都被禁止了.在修改了/etc/inetd.conf之后,使用命令kill -HUP (inetd的进程号),使inetd重新读取配置文件并重新启动即可.

5. ip route的配置

利用linux,一台普通的微机也可以实现高性价比的路由器.首先让我们了解一下linux的查看路由信息的命令:

[root@ice /etc]# route -n

Kernel IP routing table

Destination  Gateway  Genmask Flags Metric Ref Use Iface

202.112.13.2040.0.0.0  255.255.255.255 UH  0  0  0 eth0

202.117.48.43 0.0.0.0  255.255.255.255 UH  0  0  0 eth1

202.112.13.192  202.112.13.204 255.255.255.192 UG  0  0  0 eth0

202.112.13.192  0.0.0.0255.255.255.192 U  0  0  0  eth0

202.117.48.0 202.117.48.43 255.255.255.0  UG  0  0  0 eth1

202.117.48.0 0.0.0.0 255.255.255.0  U  0  0  0 eth1

127.0.0.0  0.0.0.0 255.0.0.0 U  0  0  0 lo

0.0.0.0 202.117.48.1 0.0.0.0 UG  0  0  0 eth1

命令netstat -r n 得到输出结果和route -n是一样的.它们操作的都是linux 内核的路由表.

命令cat /proc/net/route的输出结果是以十六进制表示的路由表.

[root@ice /etc]# cat /proc/net/route

Iface  Destination Gateway  Flags  RefCnt  Use Metric Mask

eth0  CC0D70CA 00000000 0005  0 0  0 FFFFFFF

eth1  2B3075CA 00000000 0005  0 0  0 FFFFFFF

eth0  C00D70CA CC0D70CA 0003  0 0  0 C0FFFFF

eth0  C00D70CA 00000000 0001  0 0  0 C0FFFFF

eth1  003075CA 2B3075CA 0003  0   0  0 00FFFFF

eth1003075CA 00000000 0001  0 0  0 00FFFFF

lo 0000007F  00000000 0001  0 0  0  000000F

eth1 00000000  013075CA 0003  0  0  0 0000000

通过计算可以知道,下面的这个路由表(十六进制)和前面的路由表(十进制)是一致的.

我们还可以通过命令route add (del )来操作路由表,增加和删除路由信息.

除了上面的静态路由,linux还可以通过routed来实现rip协议的动态路由.我们只需要打开linux的路由转发功能,在/proc/sys/net/ipv4/ip_forward文件中增加一个字符1.

三.网络的安全设置

在这一部分,再次强调一定要修改/etc/inetd.conf,安全的策略是禁止所有不需要的服务.除此之外,还有以下几个文件和网络安全相关.

(1)./etc/ftpusers ftp服务是一个不太安全的服务,所以/etc/ftpusers限定了不允许通过ftp访问linux主机的用户列表.当一个ftp请求传送到ftpd,ftpd首先检查用户名,如果用户名在/etc/ftpusers中,则ftpd将不会允许该用户继续连接.范例文件如下:

# /etc/ftpusers - users not allowed to login via ftp

root

in

daemon

adm

lp

ync

hutdown

halt

mail

ews

uucp

operator

games

obody

admin

(2)/etc/securetty 在linux系统中,总共有六个终端控制台,我们可以在/etc/securetty中设置哪个终端允许root登录,所有其他没有写入文件中的终端都不允许root登录.范例文件如下:

# /etc/securetty - tty's on which root is allowed to login

tty1

tty2

tty3

tty4

(3)tcpd的控制登录文件/etc/hosts.allow和/etc/hosts.deny

在tcpd服务进程中,通过在/etc/hosts.allow和/etc/hosts.deny中的访问控制规则来控制外部对linux主机的访问.它们的格式都是

ervice-list : hosts-list [ : command]

服务进程的名称 : 主机列表 可选,当规则满足时的操作

在主机表中可以使用域名或ip地址,ALL表示匹配所有项,EXCEPT表示除了某些项, PARANOID表示当ip地址和域名不匹配时(域名伪装)匹配该项.

范例文件如下:

#

# hosts.allow This file describes the names of the hosts which are

# allowed to use the local INET services, as decided

# by the '/usr/sbin/tcpd' server.

#

ALL : 202.112.13.0/255.255.255.0

ftpd: 202.117.13.196

in.telnetd: 202.117.48.33

ALL : 127.0.0.1

在这个文件中,网段202.112.13.0/24可以访问linux系统中所有的网络服务,主机202.117.13.196只能访问ftpd服务,主机202.117.48.33只能访问telnetd服务.本机自身可以访问所有网络服务.

在/etc/hosts.deny文件中禁止所有其他情况:

#/etc/hosts.deny

ALL : DENY : spawn (/usr/bin/finger -lp @%h | /bin/mail -s "Port Denial noted in %d-%h" root)

在/etc/hosts.allow中,定义了在所有其他情况下,linux所应该执行的操作.spawn选项允许linux系统在匹配规则中执行指定的shell命令,在我们的例子中,linux系统在发现无授权的访问时,将会发送给超级用户一封主题是"Port Denial noted in %d-%h"的邮件,在这里,我们先要介绍一下allow和deny文件中的变量扩展.

(4)/etc/issue和/etc/issue.net

在我们登录linux系统中的时候,我们常常可以看到我们linux系统的版本号等敏感信息.在如今的网络攻击行为中,许多黑客首先要收集目标系统的信息,版本号等就是十分重要的信息,所以在linux系统中一般要把这些信息隐藏起来./etc/issue和/etc/issue.net就是存放这些信息的文件.我们可以修改这些文件来隐藏版本信息.

另外,在每次linux重新启动的时候,都会在脚本/etc/rc.d/rc.local中再次覆盖上面那两个文件./etc/rc.d/rc.local文件的范例如下:

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

if [ -f /etc/redhat-release ]; then

R=$(cat /etc/redhat-release)

arch=$(uname -m)

a="a"

case "_$arch" in

_a*) a="an";;

_i*) a="an";;

esac

NUMPROC=`egrep -c "^cpu[0-9]+" /proc/stat`

if [ "$NUMPROC" -gt "1" ]; then

SMP="$NUMPROC-processor "

if [ "$NUMPROC" = "8" -o "$NUMPROC" = "11" ]; then

a="an"

else

a="a"

fi

fi

# This will overwrite /etc/issue at every boot. So, make any changes you

# want to make to /etc/issue here or you will lose them when you reboot.

#echo "" > /etc/issue

#echo "$R" >> /etc/issue

# echo "Kernel $(uname -r) on $a $SMP$(uname -m)" >> /etc/issue

cp -f /etc/issue /etc/issue.net

echo >> /etc/issue

在文件中黑体的部分就是得到系统版本信息的地方.一定要将他们注释掉.

(5)其他配置

在普通微机中,都可以通过ctl+alt+del三键的组合来重新启动linux.这样是十分不安全的,所以要在/etc/inittab文件中注释该功能:

# Trap CTRL-ALT-DELETE

#ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Copyright ©2006-2009 DbChina.Net | 鲁ICP备05031207号