修改linux端口范围ip-local-port-range_第1页
修改linux端口范围ip-local-port-range_第2页
修改linux端口范围ip-local-port-range_第3页
修改linux端口范围ip-local-port-range_第4页
修改linux端口范围ip-local-port-range_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

修改linux端⼝范围ip_local_port_rangetags:ip_local_port_range端⼝范围sysctlLinux中有限定端⼝的使⽤范围,如果我要为我的程序预留某些端⼝,那么我需要控制这个端⼝范围,本⽂主要描述如何去修改端⼝范围。12/proc/sys/net/ipv4/ip_local_port_range的原⽂解释:The/proc/sys/net/ipv4/ip_local_port_rangedefinesthelocalportrangethatisusedbyTCPandUDPtraffictochoosethelocalport.Youwillseeintheparametersofthisfiletwonumbers:ThefirstnumberisthefirstlocalportallowedforTCPandUDPtrafficontheserver,thesecondisthelastlocalportnumber.Forhigh-usagesystemsyoumaychangeitsdefaultparametersto32768-61000-first-last./proc/sys/net/ipv4/ip_local_port_range定义了本地tcp/udp的端⼝范围。可以理解为系统中的程序会选择这个范围内的端⼝来连接到⽬的端⼝(⽬的端⼝当然是⽤户指定的)。12[root@localhost~]#cat/proc/sys/net/ipv4/ip_local_port_range3276861000可以看到,现在定义的范围是32768-61000.如果想修改这个范围,可以使⽤sysctl⼯具,sysctl的配置⽂件位于/etc/sysctl.conf。先看⼀下man中的描述12345678910111213141516171819202122232425262728293031323334[root@kedacommcu]#mansysctlSYSCTL(8)SYSCTL(8)NAMEsysctl-configurekernelparametersatruntimeSYNOPSISsysctl[-n][-e]variable...SYSCTL(8)SYSCTL(8)NAMEsysctl-configurekernelparametersatruntimeSYNOPSISsysctl[-n][-e]variable...sysctl[-n][-e][-q]-wvariable=value...sysctl[-n][-e][-q]-p<filename>sysctl[-n][-e]-asysctl[-n][-e]-ADESCRIPTIONsysctlisusedtomodifykernelparametersatruntime.Theparametersavailablearethoselistedunder/proc/sys/.Procfsisrequiredforsysctl(8)supportinLinux.Youcanusesysctl(8)tobothreadandwritesysctldata.PARAMETERSvariableThenameofakeytoreadfrom.Anexampleiskernel.ostype.The??separatorisalsoacceptedinplaceofa??variable=valueTosetakey,usetheformvariable=value,wherevariableisthekeyandvalueisthevaluetosetitto.Ifthevaluecontainsquotesorcharacterswhichareparsedbytheshell,youmayneedtoenclosethevalueindoublequotes.Thisrequiresthe-wparametertouse.-nUsethisoptiontodisableprintingofthekeynamewhenprintingvalues.-eUsethisoptiontoignoreerrorsaboutunknownkeys.34353637383940414243444546474849505152535455565758596061printthenames.Itmaybeusefulwithshellsthathaveprogrammablecompletion.-NUsethisoptiontoonly-qUsethisoptiontonotdisplaythevaluessettostdout.-wUsethisoptionwhenyouwanttochangeasysctlsetting.-pLoadinsysctlsettingsfromthefilespecifiedor/etc/sysctl.confifnonegiven.Specifying-asfilenamemeansreadingdatafromstandardinput.-aDisplayallvaluescurrentlyavailable.-ASameas-aEXAMPLES/sbin/sysctl-a/sbin/sysctl-nkernel.hostname/sbin/sysctl-wkernel.domainname=""/sbin/sysctl-p/etc/sysctl.confNOTESPleasenotethatmodulesloadedaftersysctlisrunmayoverridethesettings(example:sunrpc.*settingsareoverriddenwhenthesunrpcmoduleisloaded).Thismaycausesomeconfusionduringbootwhenthesettingsinsysctl.confmaybeoverriden.Topreventsuchasituation,sysctlmustberunaftertheparticularmoduleisloaded(e.g.,from/etc/rc.d/rc.localorbyusingtheinstalldirectiveinmodprobe.conf)配置⽂件中也许没有定于范围,那么可以在⽂件中加上,见最后的#test段:123456789101112131415161718192021222324252627282930313233[root@localhost~]#vim/etc/sysctl.conf#KernelsysctlconfigurationfileforRedHatLinux##Forbinaryvalues,0isdisabled,1isenabled.Seesysctl(8)and#sysctl.conf(5)formoredetails.#ControlsIPpacketforwardingnet.ipv4.ip_forward=0#Controlssourcerouteverificationnet.ipv4.conf.default.rp_filter=1#Donotacceptsourceroutingnet.ipv4.conf.default.accept_source_route=0#ControlstheSystemRequestdebuggingfunctionalityofthekernelkernel.sysrq=0#ControlswhethercoredumpswillappendthePIDtothecorefilename#Usefulfordebuggingmulti-threadedapplicationskernel.core_uses_pid=1#ControlstheuseofTCPsyncookiesnet.ipv4.tcp_syncookies=1#Controlsthemaximumsizeofamessage,inbyteskernel.msgmnb=65536#Controlsthedefaultmaxmimumsizeofamesagequeuekernel.msgmax=65536#Controlsthemaximumsharedsegmentsize,inbyteskernel.shmmax=6871947673633343536373839#Controlsthemaximumnumberofsharedmemorysegments,inpageskernel.shmall=4294967296#testnet.ipv4.ip_local_port_range=3276859000修改后,可以使⽤以下命令重新加载123456789101112[root@localhost~]#sysctl-p/etc/sysctl.confnet.ipv4.ip_forward=0net.ipv4.conf.default.rp_filter=1net.ipv4.conf.default.accept_source_route=0kernel.sysrq=0kernel.core_uses_pid=1net.ipv4.tcp_sy

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论