修改linux端口范围 ip_local_port_range
tags: ip_local_port_range 端口范围 sysctl
Linux中有限定端口的使用范围,如果我要为我的程序预留某些端口,那么我需要控制这个端口范围,
本文主要描述如何去修改端口范围。
|
1
2
|
/proc/sys/net/ipv4/ip_local_port_range的原文解释:The /proc/sys/net/ipv4/ip_local_port_range defines the local port range that is used by TCP and UDP traffic to choose the local port. You will see in the parameters of this file two numbers: The first number is the first local port allowed for TCP and UDP traffic on the server, the second is the last local port number. For high-usage systems you may change its default parameters to 32768-61000 -first-last. |
/proc/sys/net/ipv4/ip_local_port_range定义了本地tcp/udp的端口范围。可以理解为系统中的程序会选择这个范围内的端口来连接到目的端口(目的端口当然是用户指定的)。
|
1
2
|
[root@localhost ~]# cat /proc/sys/net/ipv4/ip_local_port_range 32768 61000 |
可以看到,现在定义的范围是32768-61000.
如果想修改这个范围,可以使用sysctl工具,sysctl的配置文件位于/etc/sysctl.conf 。
先看一下man中的描述
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
[root@kedacom mcu]# man sysctlSYSCTL(8) SYSCTL(8)NAME sysctl - configure kernel parameters at runtimeSYNOPSIS sysctl [-n] [-e] variable ...SYSCTL(8) SYSCTL(8)NAME sysctl - configure kernel parameters at runtimeSYNOPSIS sysctl [-n] [-e] variable ... sysctl [-n] [-e] [-q] -w variable=value ... sysctl [-n] [-e] [-q] -p <filename> sysctl [-n] [-e] -a sysctl [-n] [-e] -ADESCRIPTION sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl(8) support in Linux. You can use sysctl(8) to both read and write sysctl data.PARAMETERS variable The name of a key to read from. An example is kernel.ostype. The ??separator is also accepted in place of a ?? variable=value To set a key, use the form variable=value, where variable is the key and value is the value to set it to. If the value contains quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes. This requires the -w parameter to use. -n Use this option to disable printing of the key name when printing values. -e Use this option to ignore errors about unknown keys. -N Use this option to only print the names. It may be useful with shells that have programmable completion. -q Use this option to not display the values set to stdout. -w Use this option when you want to change a sysctl setting. -p Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying - as filename means reading data from standard input. -a Display all values currently available. -A Same as -aEXAMPLES /sbin/sysctl -a /sbin/sysctl -n kernel.hostname /sbin/sysctl -w kernel.domainname="example.com" /sbin/sysctl -p /etc/sysctl.confNOTES Please note that modules loaded after sysctl is run may override the settings (example: sunrpc.* settings are overridden when the sunrpc module is loaded). This may cause some confusion during boot when the settings in sysctl.conf may be overriden. To prevent such a situation, sysctl must be run after the particular module is loaded (e.g., from /etc/rc.d/rc.local or by using the install directive in modprobe.conf) |
配置文件中也许没有定于范围,那么可以在文件中加上,见最后的#test段:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
[root@localhost ~]# vim /etc/sysctl.conf # Kernel sysctl configuration file for Red Hat Linux## For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and# sysctl.conf(5) for more details.# Controls IP packet forwardingnet.ipv4.ip_forward = 0# Controls source route verificationnet.ipv4.conf.default.rp_filter = 1# Do not accept source routingnet.ipv4.conf.default.accept_source_route = 0# Controls the System Request debugging functionality of the kernelkernel.sysrq = 0# Controls whether core dumps will append the PID to the core filename# Useful for debugging multi-threaded applicationskernel.core_uses_pid = 1# Controls the use of TCP syncookiesnet.ipv4.tcp_syncookies = 1# Controls the maximum size of a message, in byteskernel.msgmnb = 65536# Controls the default maxmimum size of a mesage queuekernel.msgmax = 65536# Controls the maximum shared segment size, in byteskernel.shmmax = 68719476736# Controls the maximum number of shared memory segments, in pageskernel.shmall = 4294967296#testnet.ipv4.ip_local_port_range = 32768 59000 |
修改后,可以使用以下命令重新加载
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@localhost ~]# sysctl -p /etc/sysctl.conf net.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_syncookies = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.ip_local_port_range = 32768 59000 |
再次查看,发现端口范围已经修改了。
|
1
2
|
[root@localhost ~]# cat /proc/sys/net/ipv4/ip_local_port_range32768 59000 |
修改linux端口范围 ip_local_port_range的更多相关文章
- Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
- 【转】Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
- Linux 修改linux的SSH的默认端口
修改linux的SSH的默认端口 by:授客 QQ:1033553122 安装完linux后,默认的情况下ssh是开放的,容易造到黑客攻击,简单有效的操作之一就是修改默认端口号 步骤一:修改/et ...
- 修改Linux SSH连接端口和禁用IP,安装DDoS deflate
测试系统:centos7 修改连接端口 修改配置文件 vi /etc/ssh/sshd_config 去掉port 22的注释,添加新的端口配置 port your_port_num 自定义端口选择建 ...
- linux系统中 redis 保存数据的5种形式 linux后端模式启动 jedis无法通过IP地址和端口号访问如何修改linux防火墙
vim修改redis.conf配置文件(我的已经复制到虚拟机的/usr/local/redis/bin目录下)为daemonize yes, 以后端模式启动 ./redis-server redis. ...
- 在Linux上安装多Jboss个需要修改的端口
如果在一台机器上部署了多个jboss server,需要修改相关端口以避免端口冲突.目前确认需要修改的配置如下一.vi $JBOSS_HOME/server/default/conf/jboss-se ...
- linux修改ssh端口 以及禁止root远程登录 (实验机 CentOs)
把ssh默认远程连接端口修改为3333 1.编辑防火墙配置: vi /etc/sysconfig/iptables 防火墙新增端口3333,方法如下: -A INPUT -m state --stat ...
- Linux 环境 搭建Git 服务器,并且修改SSH端口使用
1.环境配置说明 服务器 CentOS 7 + git(git version 1.8.3.1) 客户端 Windows10 + SourceTree 2.安装 Git 服务器端安装: sudo yu ...
- 修改Linux内核参数提高Nginx服务器并发性能
当linux下Nginx达到并发数很高,TCP TIME_WAIT套接字数量经常达到两.三万,这样服务器很容易被拖死.事实上,我们可以简单的通过修改Linux内核参数,可以减少Nginx服务器 的TI ...
随机推荐
- ASP.NET MVC4 学习系统五(Razor)
Razor ,你好! Razor 是一种把代码和内容进行平滑集成的语法.尽管它引入了一些新的符号和关键字,但是Razor并不是一种新的语法.相反,Razor允许用户使用已知的语言来编写代码 ...
- CSS 宝库
Cascading Style Sheets, 层叠样式表单或者层叠样式表.简称CSS. 目的是为了表现HTML或者XML的样式. 可以做到网页内容和表现的分离.可以说,CSS是一种表现语言. h5禁 ...
- android style 中一些颜色的定义
colorControlNormal 单选多选等控件颜色 colorControlActivated 单选多选等控件激活颜色
- makefile 中定义宏位置需要注意一下
CUR_DIR = $(shell pwd) CFLAGS = -g -Wall GCC = gcc GXX = g++ TARGET = exe.out SRC_FILES += $(shell f ...
- 深入理解JavaScript系列(转自汤姆大叔)
深入理解JavaScript系列文章,包括了原创,翻译,转载,整理等各类型文章,如果对你有用,请推荐支持一把,给大叔写作的动力. 深入理解JavaScript系列(1):编写高质量JavaScript ...
- Javascript 常用系统内置函数
1:在数组指定位置插入元素 array.splice(2, 0, "three"); //在索引2的位置,删除0个元素后,插入元素“three” 例子: // 原来的数组 va ...
- 萝卜家园32位和64位Win7系统Ghost版
新萝卜家园32位Win7系统Ghost版Sp1,官方旗舰版采用Windows7 SP1简体中文旗舰版32位(MSDN官方发布正式版原版ios镜像)制作,并能够完美自动激活,采用自由天空驱动包,解决部分 ...
- winform之excel导入和导出
引用命名空间 using Microsoft.Office.Interop.Excel;DataGridView 导出到Excel public static void SaveAs(DataGr ...
- scan的filter使用
本次操作的hbase的t1表的数据是: hbase(main)::> scan 't1' ROW COLUMN+CELL column=f1:age, timestamp=, value= co ...
- 启动hadoop报ERROR org.apache.hadoop.hdfs.server.namenode.FSImage: Failed to load image from FSImageFile
不知道怎么回事,今天在启动集群时通过jps查看进程时始终有一个standby namenode进程无法启动.查看日志时报的是不能加载fsimage文件.日志截图如下: 日志报的很明显了是不能加载元数据 ...