I have 3 servers A, B and C that already have IP addresses assigned by the DHCP server.
I wanted to request a fourth IP from the DHCP server that I can use as a floating IP between my service.
Is there a simple way to do this via python or bash/shell commands? Everything I've read is always talking about renewing the machines IP address not pooling another available IP.
Related
I need my own IP in a small script and in order not to hardcode it, I`ve found a piece of code from here(stackoverflow) that works.
This--
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
--
What is not clear for me is why it only works on UDP and not TCP? It has something to do with the google dns server? Thanks in advance.
This has nothing to do with Google and nothing to do with DNS.
All what this code does is to "connect" a UDP socket to an external IP, so that the OS kernel figures out which local IP address it needs to use in order to reach this external system. This is no real connection, i.e. there is no traffic involved but the OS kernel is only checking routing tables and local interfaces in order to decide which IP address to use as source in case one would actually use the socket to send data.
One could do the same with TCP. But in this case a real TCP connection would be established which means that actual traffic would be exchanged and that the connect would fail if the external system would not be reachable on this port (i.e. no listener, firewall in between etc).
With UDP instead connect will not produce any traffic and would fail only if no route to the destination IP address could be determined. This also means that an arbitrary external IP address and port could be used, i.e. ('1.1.1.1',11) would work the same as ('8.8.8.8',80).
I am writing a socket program to create a simple server.
When I write ip = socket.gethostbyname(socket.gethostname()) and then I print ip it prints 127.0.1.1
Why does this keep happening?
My device is connected to a mobile hotspot connection still the ip address remains of a local host.
I am using ubuntu 19.04 OS
The problem is that a host has multiple interfaces. It is not a problem is you use a true DNS or a carefully handwritten /etc/host file because then the system will look there to find the translation. But depending on the configuration, the host name can be bound to all the available interfaces, including the loopback one. And gethostbyname returns the address of the first of those interfaces in its own order.
To make sure of that, you should use gethostbyname_ex which returns a list of all the interfaces, and you should find the hostspot connected one, in addition to the loopback one.
I have a simple Apache+Flask website running inside a basic Vagrant+VirtualBox environment. I can access my site fine at 127.0.0.1:8080.
The question & problem is, how do I configure Vagrant to pass the real clients IP address to Apache+Flask?
request.remote_addr always returns 10.0.2.2 no matter what client is connecting from within my LAN.
For example the machine running Vagrants IP is 192.168.1.5. From a client i.e. another laptop on my LAN with IP of 192.168.1.7, would hit the site # 192.168.1.5:8080, but 192.168.1.7 is not the remote_addr in vagrant/flask+apache, its always 10.0.2.2
Thanks!
The most easy way to do that would be a bridged network. The VM will receive an IP address in your (outside) network, e.g. 192.168.1.10.
See https://docs.vagrantup.com/v2/networking/public_network.html on how to configure that.
I have a server running by using python's base http server. The host name used is '127.0.0.1' the local host, and the port number is set to 8000. I have the public ip address of the computer operating this server.
If I wanted to send a http get request to this from another computer, what would I type into my browser?
Sounds like you've got your server process running on the wrong interface. 127.0.0.1 is not a hostname but an IP address, specifically the local loopback address. It is not reachable from any other machine (unless something's gone tragically wrong with your network configuration).
You can run anything you like on the 127.0.0.1 interface, and no one else can directly connect to it from a remote machine. That's pretty much the point --- it's for testing programs that use the Internet Protocol, and (in recent years) for starting single-user servers without worrying about security. (Python 2's SimpleHTTPServer does this, as do some personal wikis, and I think iPython Notebook.)
The public address for the host running your Web server is a completely unrelated network interface, with its own hardware and its own port 8000. It doesn't know or care that you've got something listening on some other interface's port 8000, so it should refuse attempts to connect to that port.
Since you didn't post any code, I have no idea what you need to change to get your server running on the correct interface. Assuming you've more or less followed the example in the BaseHTTPServer.HTTPServer docs:
def run(
server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler,
):
server_address = ('', 8000) # <----= Replace the string.
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
That server_address tuple is a string containing the IP address ('1.2.101.202' or whatever), followed by an integer port number. So replace the string with your host machine's public-facing IP address.
Note that port 8000 is outside the reserved range (0 up to but not including 1024), so it's possible that some unrelated service is already using that port. (Numerous applications are already squatting port 8000.) If so, you'll just have to choose another port number. You can chose anything from 1024 up to but not including 65536, but as with 8000, someone else might already be using it.
Depending on your operating system and its security setup, you might not have permission to open a socket that listens on an arbitrary port number. If so, that's between you and your ISP or sysadmin.
http://yourip:port/func
yourip is your public ip.
port is 8080
func is your registered function.
and also make sure you port is opened
I wish to demonstrate a DNS cache poisoning attack. For this, I have configured a DNS server on a VM. I am trying to delay incoming traffic from the following IP addresses to the VM: 199.43.133.53 and 199.43.132.53 using tc and the following commands:
modprobe ifb
ip link set dev ifb0 up
tc qdisc add dev eth0 ingress
tc filter add dev eth0 parent ffff: protocol ip u32 \
match ip src 199.43.132.53/16 flowid 1:1 action mirred egress redirect dev ifb0\
tc qdisc add dev ifb0 root netem delay 5000ms
The two IP addresses correspond to the nameservers of a domain. When I ping these two nameservers from the VM after adding these rules, it does get a delayed response which is fine. What I wish to delay is the DNS response from these nameservers. And this is still pretty fast.
I am also running a python script on the host machine which sends packets to this VM. When these rules are added to the VM, the python script ( uses Scapy and sendp to write packets) also experiences a delay. Though when I ping the VM from host machine, the ping response is pretty fast. Why does Python's sendp experience a delay when the host machine's IP is not a part of the filter. And in that case, why is the ping response (ping request from host to VM) normal and not delayed. What am I missing here?