I could not understand you properly. I assume you are asking for gateway and restriction facilities. For that forget Ubuntu and use the ready made packages available like Pfsense, smoothwall, ipcop or else if you wanna filter out only some IPs then you can use some shell scripting.