ipv4

Efficient way to store IPv4/IPv6 addresses

北慕城南 提交于 2019-12-01 16:54:12
I am working on a C/C++ networking project that it should be able to both use the IPv4 and IPv6 networking stacks. The project works only on Linux. So, I tried to find an efficient way to store the IP addresses and differentiate between the protocol families. The first approach was to have a union: struct ip_addr { uint8_t fam; // socket family type union { struct in_addr ipv4_sin_addr; struct in6_addr ipv6_sin_addr; }addr; }; The second approach was to define a typedef std::vector<unsigned char> IPAddressNumber and make the difference after the number of bytes from the vector. The third

linux系统调优及安全设置

末鹿安然 提交于 2019-12-01 16:43:51
Linux系统调优及安全设置 1、更改yum源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup <<-备份系统自带yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo <<—国内使用阿里云yum源速度比较快 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 注:镜像官方网址http://mirrors.aliyun.com/ 如有自建yum仓可以更改成自建yum仓地址信息 2、关闭selinux 永久关闭(需要重启系统) sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 临时关闭(无需重启) setenforce 0 数字0表示Premissive,即给出警告提示,不会阻止操作,相当于disabled 数字1表示Enfocing,即表示SELinux为开启状态 getenforce <<-查看selinux当前状态 3、关闭iptables /etc/init

Node.js dns.resolve() vs dns.lookup()

穿精又带淫゛_ 提交于 2019-12-01 15:42:48
I need to lookup a given host to its corresponding IP in Node.js. There seems to be two native methods of doing this: > dns.resolve('google.com', (error, addresses) => { console.error(error); console.log(addresses); }); QueryReqWrap { bindingName: 'queryA', callback: { [Function: asyncCallback] immediately: true }, hostname: 'google.com', oncomplete: [Function: onresolve], domain: Domain { domain: null, _events: { error: [Function] }, _eventsCount: 1, _maxListeners: undefined, members: [] } } > null [ '216.58.194.174' ] And: > dns.lookup('google.com', (error, address, family) => { console

大数据 负载均衡LVS 配置

醉酒当歌 提交于 2019-12-01 12:53:44
1、准备3台虚拟机 2、先配置3台虚拟机的网络:   eth0,配置在一个网段   DIP,RIP在一个网段 3、配置lvs的VIP ifconfig eth0:0 192.168.9.100/24 echo “1” > /proc/sys/net/ipv4/ip_forward (转发数据包) 4、调整RS的响应。通告级别(每一台RS都配): echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce kernel parameter: 目标mac地址为全F,交换机触发广播 /proc/sys/net/ipv4/conf/*IF*/ arp_ignore: 定义接收到ARP请求时的响应级别; 0:只要本地配置的有相应地址,就给予响应; 1:仅在请求的目标(MAC)地址配置请求 到达的接口上的时候,才给予响应; arp_announce:定义将自己地址向外通告时的通告级别; 0:将本地任何接口上的任何地址向外通告; 1

CentOS7网络配置

泄露秘密 提交于 2019-12-01 12:27:43
CentOS7中已经取消了ifconfig,用nmcli进行了代替,服务管理也升级为systemd。所以之前在6.x版本上的网络配置操作在7.x上行不通了。 下面介绍一下在CentOS7.x上进行网络配置的方法。 环境准备:新安装的CentOS7.x,最小化安装,没有进行网络配置。 1、查看当前网卡信息 [root@localhost ~] # nmcli connection show NAME UUID TYPE DEVICE enp0s3 5 d58d8cc- 8 caf- 458 b -a 672-ed0cdf58292e 802 - 3 -ethernet --- CentOS7中对网上的命名规则有所变更,具体规则如下: eno1 :代表由主板 BIOS 內建的网卡 ens1 :代表由主板 BIOS 內建的 PCI -E 界面的网卡 enp2s0 :代表 PCI -E 界面的独立网卡,可能有多个网卡接口,因此会有 s0, s1 ... 的编号 eth0 :如果上述的名称都不适用,就回到原本的预设网卡编号 由于现在网卡没有启用,也没有建立相关的配置文件,因此在DEVICE 栏位里显示的是”—”。在配置完成,重启网络服务后就会显示相应的设备名,在我的虚拟机上显示的是“enp0s3” 2、使用nmcli命令手工配置网卡 需要配置的网络信息: IP地址:172.20.31.221

【转】sysctl命令及改变net.ipv4.ip_forward = 1方法

江枫思渺然 提交于 2019-12-01 12:17:09
转自:https://blog.csdn.net/michaelzhou224/article/details/16979285 sysctl配置与显示在/proc/sys目录中的内核参数.可以用sysctl来设置或重新设置联网功能,如IP转发、IP碎片去除以及源路由检查等。用户只需要编辑/etc/sysctl.conf文件,即可手工或自动执行由sysctl控制的功能。 命令格式: sysctl [-n] [-e] -w variable=value sysctl [-n] [-e] -p <filename> (default /etc/sysctl.conf) sysctl [-n] [-e] -a 常用参数的意义: -w 临时改变某个指定参数的值,如 sysctl -w net.ipv4.ip_forward=1 -a 显示所有的系统参数 -p 从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载 如果仅仅是想临时改变某个系统参数的值,可以用两种方法来实现,例如想启用IP路由转发功能: 1) #echo 1 > /proc/sys/net/ipv4/ip_forward 2) #sysctl -w net.ipv4.ip_forward=1 以上两种方法都可能立即开启路由功能,但如果系统重启,或执行了 # service network restart

TCP连接的超时时间

家住魔仙堡 提交于 2019-12-01 12:15:38
无论你用任何语言或者是网络库,你都可以设置网络操作的超时时间,特别是connect、read、write的超时时间。 你可以在代码中把超时时间设置任意大小值,但是connect方法会有一点特殊。 connect的超时时间在任意的内核实现上都有一个可以设置的最大值,你的代码中设置的超时值并不能超过这个最大值(即使你设置的值超过这个最大值,其仍然会在最大超时时间后time out)。 tcp建立连接的过程从客户端发送syn包开始。如果客户端没有收到这个syn包的回复,内核会重试多次发送syn包,每次重试的间隔都会逐渐增加,避免发送太多的syn包影响网络。 所有的内核对syn包发送的重复次数都有一个上限值。在BSD衍生的内核中(包括Mac OS X),会在第一次发送syn包后的6秒重试第二次,在第二次尝试后的18秒尝试第三次,如果第3次还不能成功就认为connect超时(此时经过了75秒)。 然而,在linux系统上,整个syn包发送的事件过程才差不多20几秒。linux系统比bsd类系统重发syn包的时间间隔要密。linux在20多秒内发送5个syn包(其中包括原始的syn包和后面的重发包),其依次在首包发送的3s,6s,12s,24s后发送。 如果你的程序设置的connect超时时间比20s小,那么没有问题。但是如果你的设置值大于20s,那么你会发现内核会将该值截断为20s。

Centos内核参数优化

流过昼夜 提交于 2019-12-01 12:13:32
关于内核参数优化 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_syncookies = 1 net.core.somaxconn = 262144 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_max_orphans = 262144 net.ipv4.tcp_max_syn_backlog = 262144 来源: https://www.cnblogs.com/lfl17718347843/p/11684946.html

How to force ipv6 or ipv4 for HttpWebRequest or WebRequest C#

早过忘川 提交于 2019-12-01 11:03:38
Coming from node.js I can do this to tell node.js to make the request using ipv6 vs ipv4 var http = require("http"); var options = { hostname: "google.com", family: 4, // set to 6 for ipv6 }; var req = http.request(options, function(res) { .. handle result here .. }); req.write(""); req.end(); Setting family to 4 forces ipv4, setting it to 6 forces ipv6. Not setting it lets either work. How can I do the same thing in C# (.NET 3.5) I can think of one way which is to make a DNS request myself myself for the A or AAAA records, make a direct IP request and set the host: header. Is there a better