Shouldn't it be possible? Let's assume I don't need a response, I just want to send a request. Shouldn't we be able to alter tcp/ip headers, because our computer sends it? I am probably missing something, just really curious, learning about it in the uni.
You can using the
You could spoof your ip address:
curl --header "X-Forwarded-For: 192.168.0.2" http://example.com
$ curl http://webhost.co.uk
$ tailf access.log | grep 192.168.0.54 192.168.0.54 - - [10/Nov/2014:15:56:09 +0000] "GET / HTTP/1.1" 200 14328 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/220.127.116.11 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
client with ip address changed
$ curl --header "X-Forwarded-For: 192.168.0.99" http://webhost.co.uk
$ tailf access.log | grep 192.168.0.99 192.168.0.99 - - [10/Nov/2014:15:56:43 +0000] "GET / HTTP/1.1" 200 14328 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/18.104.22.168 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
-H/--header <header> (HTTP) Extra header to use when getting a web page. You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do. You should not replace internally set headers without knowing perfectly well what you’re doing. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:".
I think the accepted answer will not really help you spoof your IP all the way. You can't really spoof your source IP unless you have access to routers close to the target machine.
TCP works on a 3-way handshake mechanism. You'll not be able to complete this handshake as the handshake response from the target machine will go to your spoofed IP and not your own (unless, as said before, you control his nearby routers and redirect the response towards yourself).
P.S.: You might be able to send a UDP message, but I haven't tried it.
It is possible to change the source IP address, if your local network interface has multiple IP addresses.
Suppose you have a server which has 2 IP addresses,
$ ip route default via 22.214.171.124 dev eth0 126.96.36.199/27 via 188.8.131.52 dev eth0 184.108.40.206/27 dev eth0 proto kernel scope link src 220.127.116.11 18.104.22.168 via 22.214.171.124 dev eth0 scope link
You can verify your current public IP address with the awesome ifconfig.co web service:
$ curl -4 ifconfig.co 126.96.36.199
To access the ifconfig.co web service using the other IP address (
188.8.131.52), you can create a route based on the target server's IP address. Use dig to find the target IP addresses from the DNS
$ dig ifconfig.co ... ifconfig.co. 39 IN A 184.108.40.206 ifconfig.co. 39 IN A 220.127.116.11 ...
Now add custom routes for these IP addresses:
$ ip route add 18.104.22.168/32 via 22.214.171.124 dev eth0 src 126.96.36.199 $ ip route add 188.8.131.52/32 via 184.108.40.206 dev eth0 src 220.127.116.11
Running curl again, you see that you are using the other source IP address:
$ curl -4 ifconfig.co 18.104.22.168
Also, your routing information is updated:
$ ip route default via 22.214.171.124 dev eth0 126.96.36.199/27 via 188.8.131.52 dev eth0 184.108.40.206/27 dev eth0 proto kernel scope link src 220.127.116.11 18.104.22.168 via 22.214.171.124 dev eth0 scope link 126.96.36.199 via 188.8.131.52 dev eth0 src 184.108.40.206 220.127.116.11 via 18.104.22.168 dev eth0 src 22.214.171.124
Note: this only works if the source IP address can be resolved to your server, otherwise the TCP 3-way handshake will fail, as pointed out here.