Archive for Linux分享

PHP Mcrypt on CentOS 6

Yay, CentOS 6 still doesn’t by default include mcrypt in it’s distribution on repositories.

There is hope, EPEL to the rescue again:

 

1
2

 

You should see EPEL listed as the repos, then:

1
yum install php-mcrypt

Also a few of you have mentioned you need to restart Apache. To do this:

1
service httpd restart

Done.

If you want to do the same for CentOS 7 then simply use this instead:

**Please note the above download is for CentOS 6 x86_64**

UPDATE 12/02/2013: Updated to Latest Link for EPEL 6.8
UPDATE 05/01/2015: Added the link for CentOS 7/EPEL 7.5

评论

Linux系统下挂载、卸载新硬盘的方法

VMware虚拟机中,Linux系统下挂载、卸载新硬盘的方法
装载:

1、启动vm,选择vm->Settings,按向导添加一块SCSI磁盘。进入Linux系统。
2、 fdisk -l 会看到有一块新的设置,如果你先前有一块硬盘(sda1, sda3…),新加的这块应该是(/dev/sdb)。 (如果添加的第二块硬盘是IDE硬盘,应该看到hdb,如果是SCSI硬盘,看到的就是应该sdb)
[root@localhost ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda3              14        1044     8281507+  83  Linux

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table

3、分区:
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m     ##在这里按m ,就会输出帮助;
Command action
a   toggle a bootable flag
b   edit bsd disklabel
c   toggle the dos compatibility flag
d   delete a partition  ##这是删除一个分区的动作;
l   list known partition types   ##:l是列出分区类型,以供我们设置相应分区的类型;
m   print this menu
n   add a new partition    ##添加一个分区;
o   create a new empty DOS partition table
p   print the partition table   ##p列出分区表;
q   quit without saving changes  ##不保存退出;
s   create a new empty Sun disklabel
t   change a partition’s system id   ##t 改变分区类型;
u   change display/entry units
v   verify the partition table
w   write table to disk and exit   ##把分区表写入硬盘并退出;
x   extra functionality (experts only)  ##扩展应用,专家功能;

Command (m for help): n
Command action
e   extended   ##扩展分区
p   primary partition (1-4) ##选p建主分区
p
Partition number (1-4): 1
First cylinder (1-17849, default 1):   ##注:这个就是分区的Start 值;这里最好直接按回车,如果你输入了一个非默认的数字,会造成空间浪费;
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-17849, default 17849):  8920
Using default value 500
##这个是定义分区大小的,+200M 就是大小为200M ;当然你也可以根据上面提示的单位cylinder的大小来算,然后来指定 End的数值,在fdisk –l命令中可以看到Units = cylinders of 16065 * 512 = 8225280 bytes,这个就是单位cylinder的大小,我这里选的End的数值是8920,正好是总大小的一半,71G左右

##然后再来建一个主分区
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (8921-17849, default 8921):8921
Using default value 8921
Last cylinder or +size or +sizeM or +sizeK (8921-17849, default 17849):17849
Using default value 17849
##最后保存并退出,切记,一定要保存,不然不会生效的。
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
##使用fdisk –l命令来查看磁盘状况:
[root@localhost ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda3              14        1044     8281507+  83  Linux

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8920    71649868+  83  Linux
/dev/sdb2            8921       17849    71722192+  83  Linux
##磁盘/dev/sdb已经被划分为2个分区,每个分区大小大概是71G左右。

##在挂载文件系统之前,需要将/dev/sdb1和/dev/sdb2重新用mkfs -t ext3 命令格式化一下,否则在挂载时会报错。
4、格式化分区:使用mkfs.ext3    /dev/sdb命令格式化磁盘 注:也可以使用mkfs -t ext3 /dev/sdb命令
[root@localhost ~]# mkfs -t ext3  /dev/sdb1     ##指将该磁盘格式化成ext3文件系统
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

补充:挂载
挂载文件系统,目前有两种方法:
一是通过 mount 来挂载,使用mount挂载系统,一旦系统重启之后就需要重新挂载。
二是通过/etc/fstab文件来开机自动挂载。
我把/dev/sdb1挂载到/test下
[root@localhost ~]# mkdir /test ## 首先建立挂载的目录test
(或者[root@localhost ~]# cd /
[root@localhost ~]# mkdir test
)
[root@localhost ~]# df –h ##挂载前的分区
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G  5.8G  576M  92% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 233M     0  233M   0% /dev/shm
[root@localhost ~]# mount /dev/sdb1 /test
[root@localhost ~]# df –h  ##挂载后的分区
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G  5.8G  576M  92% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 233M     0  233M   0% /dev/shm
/dev/sdb1             7.9G  147M  7.4G   2% /test
6、通过/etc/fstab文件来开机自动挂载(不然重启电脑后系统将不会保存之前的挂载操作):
[root@localhost ~]# vi /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
sysfs                   /sys                    sysfs   defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
/dev/sdb1            /test           ext3       defaults              1 1
/dev/sdb2            /test           ext3       defaults              1 1
# Beginning of the block added by the VMware software
.host:/                 /mnt/hgfs               vmhgfs  defaults,ttl=5     0 0
# End of the block added by the VMware software
第一字段:设备名,在这里表示是文件系统; 有时我们把挂载文件系统也说成挂载分区;
第二字段:文件系统的挂载点;
第三字段:文件系统类型;
第四字段:mount 命令的选项,和mount 中的-o 同理;defaults包括这些选项 rw, suid, dev, exec, auto, nouser, async;
第五字段:表示文件系统是否需要dump 备份,1是需要,0 是不需要;
第六字段: 是否在系统启动时,通过fsck磁盘检测工具来检查文件系统,1是需要,0是不需要,2是跳过;

卸载:
[root@localhost ~]# umount /dev/sdb1
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G  5.8G  576M  92% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 233M     0  233M   0% /dev/shm

 

补充知识:
1. mount可以用来挂载什么:
不同的操作系统使用不同的文件系统格式。MS-DOS支持FAT16文件系统,Windows98支持FAT16、FAT32文件系 统,WindowsNT支持FAT16、NTFS文件系统,Windows2000则支持FAT16、FAT32、NTFS三种文件系统格式,现在的xp 可以支持FAT32,NTFS,现在最新版本的windows 7 引入了新的WinFS文件系统。 而 Linux差不多支持所有的文件系统格式,但一般使用ext2或ext3文件系统。很多用户使用的是windows操作系统,如果想在运行的Linux下 访问其它文件系统中的资源的话,就要用Linux mount命令来实现。
2. mount使用格式:
mount命令[-参数] [设备名称] [挂载点]
说明:
[挂载点]必须是一个已经存在的目录,这个目录可以不为空,但挂载后这个目录下以前的内容将不可用,umount以后会恢复正常。
[设备名称] 可以是一个分区,一个usb设备,光驱,软盘,网络共享等。
常见参数说明:
Mount 挂载文件系统使用帮助
参数                 说明
挂载指定的设备类型:adfs, affs, autofs, coda, coherent, cramfs,

devpts, efs, ext, ext2, ext3, hfs, hpfs, iso9660, jfs, minix,

msdos, ncpfs, nfs, nfs4, ntfs, proc, qnx4, ramfs, reiserfs,

romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs,

xiafs

一般文件类型,可以不需要指定就可以有相同自动检测(adfs, bfs,

cramfs, ext, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, ntfs,

qnx4, reiserfs, romfs, udf, ufs, vxfs, xfs, xiafs 等文件系统),如

果探测失败,就将访问/etc/filesystems ,以指定文件系统探测。说

明:如果清楚文件系统,最好指定具体类型。探测错误将带来灾难性

的。
多个文件系统可以用“,”分割开来.

-t vfstype     mount -a -t nomsdos,ext
将挂载fstab文件指定所有的文件系统,除了类型为 msdos 和 ext 的

那一些。
常见文件类型
1. ext2 linux目前常用的文件系统
2. msdos MS-DOS的fat,就是fat16 vfat
3. windows98常用的fat32
4. nfs 网络文件系统
5. smbfs windows共享系统
6. iso9660 CD-ROM光盘标准文件系统
7. ntfs windows NT/2000/XP的文件系统
8. auto 自动检测文件系统
指定挂载系统选项:多个选项可以用”,”分割.某些选项只有在出现在文件 /etc/fstab 中时才有意义。下列选项可以用于任何要挂载的文件系统(但是并非所有文件系统都关心它们,例如,选项 sync 在今天只对 ext2,ext3 和 ufs 有效)
选项     说明
async 所有对文件系统的 I/O 操作都必须是异步完成的。
atime 每次存取时更新 inode 存取时间。这是默认选项。
auto 可以在使用 -a 选项时被挂载。
defaults 包含以下选项:rw, suid, dev, exec, auto, nouser,async.
dev 解析文件系统中的字符设备或块设备。
exec 允许执行二进制文件
_netdev 文件系统居于需要网络连接的设备上,避免断网下,不断挂载耗资源
noatime 不更新文件系统的inode存取时间(提升新闻服务器的速度)
noauto 只能被显式地挂载,-a不能使它挂载
nodev 不解析文件系统中的字符设备或块设备
noexec 不允许执行被加载的文件系统中的任何二进制文件
nosuid 不允许set-user-identifier 或set-group-identifier位起作用
nouser  禁止普通的挂载文件系统(默认)
remount 试图重新挂载一个已经挂载的文件系统。通常用来改变挂载标记,如由只读挂载改成可读写的。
ro  以只读方式挂载
rw 以读写方式挂载
suid 允许set-user-identifier 或set-group-identifier位起作用
-o options  sync 以同步方式进行I/O操作,突然断电不会掉资料,但加重磁盘负担
dirsync 所有对文件系统内目录的更新应当是同步完成的,影响下列系统调用:creat,link, unlink, symlink, mkdir, rmdir, mknod 以及 rename
user 允许普通的用户挂载文件系统,挂载者的用户名被写入mtab,从而使他可以再次卸载文件系统。这个选项暗含了选项noexec,nosuid, 以及 nodev.
users 允许每个用户挂载卸载文件系统
codepage codepage=XXX代码页
iocharset iocharset=XXX 字符集
loop 挂载回旋设备 经常挂载iso文件用到
username username=user 访问设备的用户名
password password=pass 访问设备的密码
以下参数只对特殊文件系统有用:
uid/gid uid=value 和 gid=value 以特殊用户及组 挂载系统
ownmask ownmask=value owner权限的权限掩码
othmask othmask=value othmask权限的权限掩码
不同文件系统所支持的属性不一定系统。可以查找相关资料
-a              搜索/etc/fstab文件中满足条件的文件系统,进行挂载操作。
格式: mount -a -t type -o options 不需要指定设备/目录
-f              测试mount系统,只检查设备和目录,并不真正挂载文件系统
-n              不把挂载的记录,记录在/etc/mtab 文件中
-r              将文件系统安装为只读,同(-o ro)
-w     将文件系统安装为可读写,同(-o rw)
-L label   挂载具有指定卷标 label 的分区
-w     将文件系统安装为可读写,同(-o rw)
-v       显示详细的挂载进度
-l     列出所有已经挂载的文件系统列表

–bind          将文件层次的一部分重新挂载到其他地方.只挂接单一的文件系统,
如果目录有其它文件系统,将不能挂载。如果需要都挂载,可以用:–rbind 参数。
mount –bind olddir newdir 2个目录可以访问系统内容
–move    将一个目录移到另外地方,mount –move olddir newdir
-h     显示帮助
-V     显示版本

3. 常见分区加载方法:
mount挂载iso文件:
#mkdir /mnt/iso1
#mount –o loop linuxsetup.iso /mnt/iso1
在linux 不需要虚拟光驱,就可以直接读取iso文件了。
mount挂载光驱系统
一般来说CDROM的设备文件是/dev/hdc,使用方法:
#mkdir /mnt/cdrom
#mount /dev/hdc /mnt/cdrom –o iocharset=cp936
默认不指定光驱系统,可以自动搜索得到,将编码指定为中文
mount挂载软驱
# mkdir /mnt/floppy
# mount /dev/fd0 /mnt/floppy
默认不指定文件系统,可以自动搜索得到
mount挂载windows共享文件(samba)
#mkdir /mnt/winshare
#mount -t smbfs -o username=w,password=w,codepage=936,iocharset=gb2312 //192.168.0.101/share /mnt/winshare
指定访问共享的用户名,密码,codepage指定编码与iocharset同意义。这里的windows 系统是中文简体。
codepage指定文件系统的代码页,简体中文中文代码是936;iocharset指定字符集,简体中文一般用cp936或gb2312
mount挂载u盘
如果计算机没有其它SCSI设备和usb外设的情况下,插入的U盘的设备路径是 /dev/sda1,用命令:
#mkdir /mnt/upan
#mount /dev/sda1 /mnt/upan
挂载即可。
mount挂载nfs系统
与windows共享连接差不多。需要正确配置服务端的nfs服务。然后通过客户端的:showmount -e 192.168.0.30 可以查看连接。
mount -t nfs 192.168.0.30:/tmp /mnt/nfs
umount卸载文件系统
umount  dir
如上面: umout /mnt/upan或者umount /dev/sdb1

评论

XenServer 创建SR存储与挂载本地ISO文件

SSH登录Xenserver。

1) 查看卷组信息:
# vgdisplay

2) 记下VGname:
VG_XenStorage-a009e816-aa69-b507-71bf-b89409c63793

3) 创建逻辑卷分配大小与命名并格式化:
# lvcreate -L 20G -n iso VG_XenStorage-a009e816-aa69-b507-71bf-b89409c63793
# mkfs.ext3 /dev/VG_XenStorage-a009e816-aa69-b507-71bf-b89409c63793/iso

5) 创建本地挂载目录
# mkdir /iso

6) 编辑/etc/fstab设置自动挂载逻辑卷
# vi /etc/fstab

添加以下内容
/dev/VG_XenStorage-a009e816-aa69-b507-71bf-b89409c63793/iso /iso ext3 defaults 0 0

7) 挂载逻辑卷
# mount /iso

8) 创建xenserver本地iso库(SR存储库)
# xe sr-create name-label=iso type=iso device-config:location=/iso device-config:legacy_mode=true contente-type=iso

9) Xenserver挂载iso
# xe-mount-iso-sr /iso -o bind

这一过程就完成了,cd /iso wegt ISO系统文件,
之后在创建虚拟机(VM)时,在安装介质那过程就可以先择对应挂载的iso安装即可。

#xe-toolstack-restart

评论

密码保护:ssssssss 使用方法

此内容受密码保护。如需查阅,请在下列字段中输入您的密码。

要查看留言请输入您的密码。

删除 Exim 邮件队列所有邮件

执行命令:
# exim -bp | exiqgrep -i | xargs exim -Mrm
就可以删除 Exim 的邮件队列的所有邮件

查看所有邮件可使用命令:
# exim -bp

cPanel面板服务器也可以通过 ConfigServer Mail Queues 来查看和删除邮件,比较直观,但是当邮件数量大时不如命令的效率高。

评论

Linux下使用parted分区工具为大于2T硬盘分区

目的:在centos 5.4系统下,用parted功能分区12T的硬盘并格式化成ext4,12T共分为2个分区,一个7.5T,另一个4.5T.
在linux 下大磁盘的分区不能再采用fdisk了,MBR分区表只支持2T磁盘,所以大于2T的磁盘必须使用GPT分区表。下面说明下具体的步骤:
1.分为两个主分区

 

[root@localhost ~]# parted /dev/sdb # 使用parted来对GPT磁盘操作,进入交互式模式
GNU Parted 1.8.1 Using /dev/sdb Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) mklabel gpt           # 将MBR磁盘格式化为GPT
(parted) print                       #打印当前分区
(parted) mkpart primary 0 4.5TB                # 分一个4.5T的主分区
(parted) mkpart primary 4.5TB 12TB      # 分一个7.5T的主分区
(parted) print                         #打印当前分区
(parted) quit 退出
Information: Don’t forget to update /etc/fstab, if necessary.

 

2.然后格式化成ext4,需要安装包e4fsprogs.x86_64(yum install e4fsprogs.x86_64)即可

[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb2

 

3.接着用mount挂载分区

[root@localhost]# mount -t ext4 /dev/sdb1 /bk
[root@localhost]# mount -t ext4 /dev/sdb2 /mail
[root@localhost ~]# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda6     ext3     39G  9.4G   28G  26% /
/dev/sda1     ext3    122M   13M  103M  12% /boot
none         tmpfs   1004M     0 1004M   0% /dev/shm
/dev/sdb1     ext4    4.1T   194M  3.9T  1% /bk
/dev/sdb2     ext4    6.8T   179M  6.4T  1% /mail

 

4.最后修改/etc/fstab,添加如下两行,让其开机自动挂载.

/dev/sdb1       /bk          ext4            defaults,noatime       1 2
/dev/sdb2      /mail       ext4           defaults,noatime         1 2

 

评论

SSLv3 再次爆出漏洞

SSLv3 再次爆出漏洞,在 Google 的新草案 TLS_FALLBACK_SCSV 还未明朗的情况下,目前禁用 SSLv3 是一个 不考虑 IE6 的 workaround。

1
2
3
4
5
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHERSAAES256SHA384:AES256SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

 

sslv3测试http://foundeo.com/products/iis-weak-ssl-ciphers/test.cfm

评论

linux下shell显示-bash-4.1#不显示路径解决方法

在linux shell中不显示路径了,显示为-bash-4.1#用起来很不方便。

如何改为显示路径的shell呢?

步骤如下:

vim ~/.bash_profile

(不用管.bash_profile这个文件有几个,自己新建一个也是可以的)

在最后加上
export PS1='[\u@\h \W]\$’

然后执行
source ~/.bash_profile

这样shell就可以显示路径了。

评论

SSH bash紧急安全补丁!重要!

注意:也许你的服务器自动更新了,看不到漏洞.但为了安全,还是建议测试下是否存在.

本文章适合所有VPS/独立服务器系统更新。

日前Linux官方内置Bash中新发现一个非常严重安全漏洞(漏洞参考https://access.redhat.com/security/cve/CVE-2014-6271  ),黑客可以利用该Bash漏洞完全控制目标系统并发起攻击,为了避免您Linux服务器受影响,建议您尽快完成漏洞修补,修复方法如下,请了解!

【已确认被成功利用的软件及系统 
所有安装GNU bash 版本小于或者等于4.3的Linux操作系统。 


【漏洞描述】 
该漏洞源于你调用的bash shell之前创建的特殊的环境变量,这些变量可以包含代码,同时会被bash执行。 


【漏洞检测方法】

 

SSH执行命令:

env t='() { :;}; echo You are vulnerable.’ bash -c “true”
修复前检测:

如果显示You are vulnerable,很遗憾,必须立即打上安全补丁修复

使用修补方案修复后
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x’
this is a test
特别提示:该修复不会有任何影响,如果您的脚本使用以上方式定义环境变量,修复后您的脚本执行会报错。

【建议修补方案 】

请您根据Linux版本选择您需要修复的命令, 为了防止意外情况发生,建议您执行命令前先对Linux服务器系统盘打个快照,如果万一出现升级影响您服务器使用情况,可以通过回滚系统盘快照解决。




2.修复漏洞办法

Ubuntu or Debian 请执行

  1. apt-get update
  2. apt-get upgrade



RedHat, CentOS or Fedora 请执行

  1. yum clean all
  2. yum -y update bash

评论

Linux下SSH用FTP命令上传文件至另一个FTP空间

如果没有ftp 提示: -bash: ftp: command not found
请先安装ftp应用程序: yum install ftp
#ftp 127.0.0.1 21 输入远程空间的FTP IP和端口号,回车
然后根据提示输入用户名和密码即可!
ftp>lcd 本地工作目录
ftp>cd 远程目录
ftp>binary 采用二进制传输
ftp> tick 开启传输时的字节计数器,再执行一次即可关闭
ftp>mput 文件

FTP> bye(或by) 结束和远程电脑的linux中ftp命令参数会话并退出linux中ftp命令参数。

FTP> cd 更改远程电脑上的工作目录。

FTP> get 使用当前文档转换类型将远程文档复制到本地电脑。
格式:get remote-file [local-file]

FTP >lcd 更改本地电脑上的工作目录。默认情况下,工作目录是启动linux中ftp命令参数的目录。

格式:lcd [directory]

FTP >ls 显示远程目录文档和子目录的缩写列表。

FTP >mdelete 删除远程电脑上的文档。
格式:mdelete remote-files [ …]
说明:remote-files 指定要删除的远程文档。

FTP >mdir 显示远程目录文档和子目录列表。能够使用 mdir 指定多个文档。
格式:mdir remote-files [ …] local-file
说明:remote-files 指定要查看列表的目录。必须指定 remote-files。请键入 – 使用远程电脑上的当前工作目录。

1、连接ftp服务器

格式:ftp [hostname | ip-address]
a)在linux命令行下输入:ftp www.boluo.org
b)服务器询问你用户名和口令,分别输入用户名和相应密码,待认证通过即可。

2、下载文件

下载文件通常用get和mget这两条命令:

a) get 格式:get [remote-file] [local-file]
将文件从远端主机中传送至本地主机中.
如要获取服务器上/ftp/1.rar,则
ftp> get /ftp/1.rar 1.rar (回车)

b) mget 格式:mget [remote-files]
从远端主机接收一批文件至本地主机.
如要获取服务器上/ftp下的所有文件,则
ftp> cd /ftp
ftp> mget *.* (回车)

注意:文件都下载到了linux主机的当前目录下。

3、上传文件

a) put 格式:put local-file [remote-file]
将本地一个文件传送至远端主机中.
如要把本地的1.zip传送到远端主机/ftp,并改名为1.rar
ftp> put 1.zip /ftp1.rar (回车)

b) mput 格式:mput local-files
将本地主机中一批文件传送至远端主机.
如要把本地当前目录下所有rar文件上传到服务器/ftp 下
ftp> cd /ftp (回车)
ftp> mput *.rar (回车)

4、断开连接

bye:中断与服务器的连接。

评论

利用iptables防止php-ddos对外udp发包

利用iptables防止php-ddos对外udp发包
最近php-ddos泛滥,尤其是织梦一堆洞洞,你懂得,我们可以利用iptables,从根源上禁止php-ddos对外发包。

 

首选允许需要UDP服务的端口(如DNS)

 iptables -I OUTPUT -p udp –dport 53 -d 8.8.8.8 -j ACCEPT
iptables -I OUTPUT -p udp –dport 53 -d 8.8.4.4 -j ACCEPT

“53”,为DNS所需要的UDP端口,“8.8.8.8”部分为DNS IP,根据您服务器的设定来定,若您不知您当前服务器使用的DNS IP,可在SSH中执行以下命令获取:

cat /etc/resolv.conf |grep nameserver |awk ‘NR==1{print $2 }’

禁止本机对外发送UDP包

iptables -A OUTPUT -p udp -j DROP

评论

在CentOS下安装OpenVZ

初次接触OpenVZ是在挑选VPS的时候,OpenVZ的VPS要比Xen的便宜不少。经过了解发现OpenVZ是操作系统层的虚拟产品,与Xen、KVM、Huper-V等虚拟化产品完全是两个不同层次的。OpenVZ提供的只是一个虚拟的环境(VE),OpenVZ自己称它为容器(Container),Xen、KVM等提供的是具有Hypervisor的虚拟机,OpenVZ对于便宜的低端VPS来说确实比较好,Xen等虚拟化产品则一般使用在企业级的应用中心、云计算平台等。

安装OpenVZ

环境:使用CentOS5.6_x86_64操作系统安装在DELL的一台PC机上。

 

官网(http://wiki.openvz.org/)给出了一个yum的源来在CentOS上进行安装,我们来调整yum源,且为了安全问题,支持OpenVZ对于CentOS5的内核补丁支持的内核版本必须大于等于2.6.18.308.8.2.el5,可以到此处查看支持的内核版本http://wiki.openvz.org/Download/kernel

[root@openvz yum.repos.d]# cd /etc/yum.repos.d
[root@openvz yum.repos.d]# wget http://download.openvz.org/openvz.repo
[root@openvz yum.repos.d]#uname -r
2.6.18-238.9.1.el5
[root@openvz yum.repos.d]#yum install kernel.x86_64   #升级内核到2.6.18.308,
[root@openvz yum.repos.d]#uname -r
2.6.18-308.8.2.el5

[root@openvz yum.repos.d]#cat openvz.repo   #修改openvz源,确保如下默认选择的是6.2的版本

[openvz-utils]
name=OpenVZ utilities
#baseurl=<a href="http://download.openvz.org/current/">http://download.openvz.org/current/</a>
mirrorlist=<a href="http://download.openvz.org/mirrors-current">http://download.openvz.org/mirrors-current</a>
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ
[openvz-kernel-rhel5]
name=OpenVZ RHEL5-based kernel
#baseurl=http://download.openvz.org/kernel/branches/rhel5-2.6.18/current/
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel5-2.6.18
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ
[root@openvz ~]# yum install ovzkernel -y#安装openvz内核
[root@openvz ~]# yum install vzctl vzquota#安装openvz的2个常用工具

由于我们的VE需要访问外部网络,所以这里先打开包转发,在后面会说到。

[root@openvz ~]# grep ip_forward /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@openvz ~]#

查看grub.conf设置的默认启动内核

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title OpenVZ (2.6.18-308.8.2.el5.028stab101.1)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-308.8.2.el5.028stab101.1 ro root=LABEL=/ selinux=0#已经自动设置关闭selinux了
        initrd /initrd-2.6.18-308.8.2.el5.028stab101.1.img
[root@openvz ~]# init 6

确保vz服务开机启动

[root@openvz ~]# service vz status
OpenVZ is running...
[root@openvz ~]# chkconfig --list vz
vz                 0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@openvz ~]#

安装管理VE

OpenVZ是使用vzctl来管理VE的,我们来看其详细命令。

[root@openvz ~]# vzctl
vzctl version 3.3
Copyright (C) 2000-2012, Parallels, Inc.
This program may be distributed under the terms of the GNU GPL License.
Usage: vzctl [options] <command> <ctid> [parameters]
vzctl create <ctid> [--ostemplate <name>] [--config <name>]
   [--layout ploop|simfs] [--hostname <name>] [--name <name>] [--ipadd <addr>]
   [--diskspace <kbytes>] [--private <path>] [--root <path>]#创建VE
vzctl start <ctid> [--force] [--wait]#启动VE
vzctl destroy | mount | umount | stop | restart | status <ctid>#关闭VE
vzctl convert <ctid> [--layout ploop[:mode]] [--diskspace <kbytes>]
vzctl quotaon | quotaoff | quotainit <ctid>#设置qutoa
vzctl console <ctid> [ttyno]#进入VE
vzctl enter <ctid> [--exec <command> [arg ...]]#进入VE
vzctl exec | exec2 <ctid> <command> [arg ...]#不进入VE执行VE下的命令
vzctl runscript <ctid> <script>#为VE执行脚本
vzctl chkpnt <ctid> [--dumpfile <name>]#保存VE的状态到文件
vzctl restore <ctid> [--dumpfile <name>]#从恢复文件恢复VE的状态
vzctl set <ctid> [--save] [--force] [--setmode restart|ignore]
   [--ram <bytes>[KMG]] [--swap <bytes>[KMG]]#设置RAM
   [--ipadd <addr>] [--ipdel <addr>|all] [--hostname <name>]#添加和删除IP
   [--nameserver <addr>] [--searchdomain <name>]#指定nameserber和sercherdomain
   [--onboot yes|no] [--bootorder <N>]#设置开机启动
   [--userpasswd <user>:<passwd>]#修改VE的用户密码
   [--cpuunits <N>] [--cpulimit <N>] [--cpus <N>] [--cpumask <cpus>]
   [--diskspace <soft>[:<hard>]] [--diskinodes <soft>[:<hard>]]
   [--quotatime <N>] [--quotaugidlimit <N>]
   [--noatime yes|no] [--capability <name>:on|off ...]
   [--devices b|c:major:minor|all:r|w|rw]
   [--devnodes device:r|w|rw|none]
   [--netif_add <ifname[,mac,host_ifname,host_mac,bridge]]>]#添加桥接设备
   [--netif_del <ifname>]#删除桥接设备
   [--applyconfig <name>] [--applyconfig_map <name>]
   [--features <name:on|off>] [--name <vename>] [--ioprio <N>]
   [--pci_add [<domain>:]<bus>:<slot>.<func>] [--pci_del <d:b:s.f>]
   [--iptables <name>] [--disabled <yes|no>]#VE的防火墙设置
   [UBC parameters]

安装一个Guest,OpenVZ官方建议的安装方法,是下载其优化过的操作系统压缩包,来进行安装。在OpenVZ上保存操作系统压缩包的位置是/vz/template/cache/。操作系统压缩包的下载地址为http://wiki.openvz.org/Download/template/precreated 。我这里下载的是CentOS5_X84_64,用来安装测试。

[root@openvz ~]# ll /vz/template/cache/
total 188092
-rw-r--r-- 1 root root 192411846 Jul 19 02:08 centos-5-x86_64.tar.gz
[root@openvz ~]# vzctl create 2 --ostemplate centos-5-x86_64 --hostname centos01
Creating container private area (centos-5-x86_64)
Performing postcreate actions
CT configuration saved to /etc/vz/conf/2.conf#配置文件保存为/etc/vz/下的2.conf
Container private area was created
[root@openvz ~]#

使用OS模版centos-5-x86_64 安装ID为2的VE,主机名为centos01,安装完成后需要修改默认的配置文件,再启动VE。

设置VE开机自启动、设置IP、设置DNS、内存、设置磁盘大小

[root@openvz ~]# vzctl set 2 --onboot yes
WARNING: Settings were not saved to config (use --save flag) #提示保存到配置文件需要--save
[root@openvz ~]# vzctl set 2 --onboot yes --save
CT configuration saved to /etc/vz/conf/2.conf
[root@openvz ~]# vzctl set 2 --ipadd 10.20.100.146 --save#此时还不能使用
CT configuration saved to /etc/vz/conf/2.conf
[root@openvz ~]# vzctl set 2 --nameserver 10.20.1.6 --save
CT configuration saved to /etc/vz/conf/2.conf
[root@openvz ~]# vzctl set 2 --ram 345 --save
Error: kernel does not support vswap, unable to use --ram/--swap parameters
Error parsing options  #内核不支持
[root@openvz ~]# vzctl set 2 --diskspace 3G:3G --save
CT configuration saved to /etc/vz/conf/2.conf
[root@openvz ~]# vzctl start 2#启动ID为2的VE
Starting container ...
Container is mounted
Adding IP address(es): 192.168.221.2
Setting CPU units: 1000
Container start in progress...
[root@openvz ~]#

使用vzlist查看VE

[root@openvz ~]# vzlist 2
      CTID      NPROC STATUS    IP_ADDR         HOSTNAME
         2         12 running   192.168.221.2   centos01

登入VE、退出VE、重启VE、启动VE、关闭VE、断电VE

[root@openvz ~]# vzctl enter 2
[root@centos01 /]# exit
[root@openvz ~]# vzctl restart 2
[root@openvz ~]# vzctl start 2
[root@openvz ~]# vzctl stop 2
[root@openvz ~]# vzctl destroy 2

不登陆VE,执行命令、执行脚本

[root@openvz ~]# vzctl  exec 2  ifconfig#不登录VE查看网卡信息
[root@openvz ~]# vzctl  runscript 2 scriptname#script在服务器上

计算VE的耗用

[root@openvz ~]# vzcalc -v 2

修改VE的root密码

[root@openvz ~]# vzctl exec 2 passwd#输入2次密码
[root@openvz ~]# vzctl set 2  --userpasswd root:123456#直接修改密码为123456

 

VE的网络

按照直接添加IP的方法,VE访问外网有2种方式来实现。一种是开启母机(用母机一词,果然比较好区分)的包转发功能,VE使用和母机同一段的IP,独立IP的VPS就是使用的这种方式,VE有自己的外网IP,用户可以登录自己的VPS进行管理;另外一种是使用路由转发功能,防火墙做snat源地址转换,VE使用私有IP,这样的话,VE可以访问外网,但是外网不能直接访问内网的VE。

方式一:公有IP

开启包转发

[root@openvz ~]# grep ip_forward /etc/sysctl.conf
net.ipv4.ip_forward = 1

使其生效

[root@openvz ~]# /sbin/sysctl -p
net.ipv4.ip_forward = 1

配置或修改VE的IP,此IP和母机在同一段(VPS中使用的是公有IP)。

[root@openvz ~]# ifconfig#母机的IP
eth0      Link encap:Ethernet  HWaddr 00:0C:29:FD:E4:AA 
          inet addr:10.20.100.141  Bcast:10.20.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:35535 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8399 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3534995 (3.3 MiB)  TX bytes:934525 (912.6 KiB)
          Interrupt:59 Base address:0x2000
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:784 (784.0 b)  TX bytes:784 (784.0 b)
venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:494 errors:0 dropped:0 overruns:0 frame:0
          TX packets:283 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:37807 (36.9 KiB)  TX bytes:23312 (22.7 KiB)
[root@openvz ~]# vzctl set 2 --ipadd 10.20.100.146 --save#修改或设置VE的IP,

测试VE的网络

[root@openvz ~]# vzctl exec 2 ifconfig
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)
venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          inet addr:127.0.0.1  P-t-P:127.0.0.1  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:224 errors:0 dropped:0 overruns:0 frame:0
          TX packets:292 errors:0 dropped:53 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:18572 (18.1 KiB)  TX bytes:23106 (22.5 KiB)
venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          inet addr:10.20.100.146  P-t-P:10.20.100.146  Bcast:10.20.100.146  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
[root@openvz ~]# vzctl exec 2 ping www.baidu.com
PING www.a.shifen.com (220.181.111.147) 56(84) bytes of data.
64 bytes from 220.181.111.147: icmp_seq=1 ttl=54 time=35.2 ms
64 bytes from 220.181.111.147: icmp_seq=2 ttl=54 time=34.9 ms

方式二:私有IP,SNAT

开启包转发

[root@openvz ~]# grep ip_forward /etc/sysctl.conf
net.ipv4.ip_forward = 1

使其生效

[root@openvz ~]# /sbin/sysctl -p
net.ipv4.ip_forward = 1

修改VE的IP,此IP为私有IP

[root@openvz ~]# vzctl set 2 --ipdel 10.20.100.146 --save#删除之前的100段IP
[root@openvz ~]# vzctl set 2 --ipadd 10.20.102.146 --save#修改或设置IP,与母机的IP段不同

开启SNAT

[root@openvz ~]# /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

或者

[root@openvz ~]# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.20.100.141
[root@openvz ~]# iptables -t nat -L#查看NAT策略
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination        
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination        
SNAT       all  --  anywhere             anywhere            to:10.20.100.141
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

查看VE网络

[root@openvz ~]# vzctl exec 2 ifconfig
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)
venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          inet addr:127.0.0.1  P-t-P:127.0.0.1  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:330 errors:0 dropped:0 overruns:0 frame:0
          TX packets:407 errors:0 dropped:53 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:26810 (26.1 KiB)  TX bytes:33397 (32.6 KiB)
venet0:1  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
          inet addr:10.20.102.146  P-t-P:10.20.102.146  Bcast:10.20.102.146  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
[root@openvz ~]#

测试VE网络

[root@openvz ~]# vzctl exec 2 ping www.baidu.com
PING www.a.shifen.com (220.181.111.147) 56(84) bytes of data.
64 bytes from 220.181.111.147: icmp_seq=1 ttl=54 time=35.0 ms
64 bytes from 220.181.111.147: icmp_seq=2 ttl=54 time=34.9 ms
[root@openvz ~]#

评论

Xen Linux VPS修改系统时间

如果你购买的是美国Xen LINUX VPS或者是其它国家的Xen LINUX VPS,那么,你首选需要查看并设置时区:

如何查看Xen LINUX VPS时区?
date -R

得到结果类似下面:
Mon, 05 Sep 2011 16:29:08 +0800

如果最后面的一段不是+800,那么你喜欢设置一下时区了,设置Xen LINUX 时区方法如下:

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

这样你的Linux VPS的时区就已经设置成中国上海-第8时区了。

有时候,买到的Xen Linux VPS不但时区不对,而且系统时间还相差很大,有时候会相关几小时。
如何修改Xen Linux VPS 时间呢?需要使用ntp时间同步软件来同步VPS系统时间。(如果你的是Xen VPS 或者是独立服务器,那么就可以修改,如果是OpenVZ VPS,则不能修改时间,只能叫机房修改母服务器的时间。)

方法命令如下:

yum install -y ntp

vi /etc/sysctl.conf

xen.independent_wallclock=1 #在文件中增加并且保存退出

sysctl -p#这步一定要记得,否则不生效。

ntpdate us.pool.ntp.org

再使用

date -R确认一下时间是否校正了.

这样时间就同步好了。

评论

CentOS一键配置iptables防火墙

CentOS一键配置iptables防火墙
手里几台VPS配置iptables太繁琐,看到了朱哥的LNMP脚本里有一个自动配置iptables防火墙的脚本,借来改了一下,给需要的人用;
只提供常用端口的设置,如果你有特殊需求只需自行添加或减少相应的端口即可;

使用方法:

wget -c http://ph4ntasy.googlecode.com/files/iptables.sh
chmod +x iptables.sh
./iptables.sh
设置iptables开机自动启动:

chkconfig –level 345 iptables on
完整Shell:

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function support_distro(){
if [ -z “`egrep -i “centos” /etc/issue`” ];then
echo “Sorry,iptables script only support centos system now.”
exit 1
fi
}
support_distro
echo “============================iptables configure============================================”
# Created by Centos.bz Modified by ph4ntasy.com
# Only support CentOS system
# 获取SSH端口
if grep “^Port” /etc/ssh/sshd_config>/dev/null;then
sshdport=`grep “^Port” /etc/ssh/sshd_config | sed “s/Ports//g” `
else
sshdport=22
fi
# 获取DNS服务器IP
if [ -s /etc/resolv.conf ];then
nameserver1=`cat /etc/resolv.conf |grep nameserver |awk ‘NR==1{print $2 }’`
nameserver2=`cat /etc/resolv.conf |grep nameserver |awk ‘NR==2{print $2 }’`
fi
IPT=”/sbin/iptables”
# 删除已有规则
$IPT –delete-chain
$IPT –flush
# 禁止进,允许出,允许回环网卡
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT ACCEPT
$IPT -A INPUT -i lo -j ACCEPT
# 允许已建立的或相关连接的通行
$IPT -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
$IPT -A OUTPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
# 限制80端口单个IP的最大连接数为10
$IPT -I INPUT -p tcp –dport 80 -m connlimit –connlimit-above 10 -j DROP
# 允许80(HTTP)/873(RSYNC)/443(HTTPS)/20,21(FTP)/25(SMTP)端口的连接
$IPT -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp –dport 873 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp –dport 443 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp –dport 20 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp –dport 21 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp –dport 25 -j ACCEPT
# 允许SSH端口的连接,脚本自动侦测目前的SSH端口,否则默认为22端口
$IPT -A INPUT -p tcp -m tcp –dport $sshdport -j ACCEPT
# 允许ping
$IPT -A INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT
$IPT -A INPUT -p icmp -m icmp –icmp-type 11 -j ACCEPT
# 允许DNS
[ ! -z “$nameserver1” ] && $IPT -A OUTPUT -p udp -m udp -d $nameserver1 –dport 53 -j ACCEPT
[ ! -z “$nameserver2” ] && $IPT -A OUTPUT -p udp -m udp -d $nameserver2 –dport 53 -j ACCEPT
# 保存规则并重启IPTABLES
service iptables save
service iptables restart
echo “============================iptables configure completed============================================”

评论

利用iptables防止php-ddos对外udp发包

利用iptables防止php-ddos对外udp发包
最近php-ddos泛滥,尤其是织梦一堆洞洞,你懂得,我们可以利用iptables,从根源上禁止php-ddos对外发包。

首选允许需要UDP服务的端口(如DNS)

iptables -I OUTPUT -p udp –dport 53 -d 8.8.8.8 -j ACCEPT
iptables -I OUTPUT -p udp –dport 53 -d 8.8.4.4 -j ACCEPT
“53”,为DNS所需要的UDP端口,“8.8.8.8”部分为DNS IP,根据您服务器的设定来定,若您不知您当前服务器使用的DNS IP,可在SSH中执行以下命令获取:

cat /etc/resolv.conf |grep nameserver |awk ‘NR==1{print $2 }’
禁止本机对外发送UDP包

iptables -A OUTPUT -p udp -j DROP

评论

« 上一页« Previous entries « 上一页 · 下一页 » Next entries »下一页 »